<?php

namespace App\Http\Controllers\Api;

use App;
use App\Util\Common;
use App\Util\GetMac;
use App\Util\SqlServerUtil;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use function Symfony\Component\Debug\header;
use Illuminate\Support\Facades\Storage;
use Excel;
use phpDocumentor\Reflection\DocBlock\Tags\Var_;

class GongziController extends CommonController
{
    protected $response = [
    		"Error" => 0,
    		"Message" => "Success!",
    		"Data" => []
	];
    
    public function getdbName(Request $request){
    	$sql="SELECT
                  [cacc_name] as text
                  ,[cdbname] as db
              FROM [master].[dbo].[t_kdaccount_gl]
            GO";
    	$res_dbs = SqlServerUtil::exec($this->SqlServer, $sql);
    	$sql="select COUNT(1) as ok  from Master..SysDatabases where name='AcctCtl'";
    	$res_ok = SqlServerUtil::exec($this->SqlServer, $sql);
    	if(isset($res_ok[0]['ok'])&&!empty($res_ok[0]['ok'])){
    		$sql="select FAcctName as text,FAcctNumber as db  from AcctCtl..t_ad_kdaccount_gl where 1=1 order by facctid";
    		$res_dbs2 = SqlServerUtil::exec($this->SqlServer, $sql);
    		
    		if(is_array($res_dbs2) && count($res_dbs2)>0) {
    			foreach ($res_dbs2 as $k => $v) {
    				array_push($res_dbs,$v);
    			}
    		}
    		$res_dbs = array_unique_fb($res_dbs, SORT_REGULAR);
    	}
    	showMsg(0,'Success!',$res_dbs);
    }
    
    public function login(Request $request){
    	$Fname = $request->get('fname');
    	$FSID = $request->get('fsid');
    	if(empty($Fname))return response()->json(Common::errorResponse(404));
    	//判断用户是否已登录 select * from t_UserW where FName = '{$Fname}' and FSID='{$FSID}'
    	// if(!$this->isloginUser($Fname))return response()->json(Common::errorResponse(404));
    	$Fname =  iconv('UTF-8', 'GBK',$Fname);
    	$sql =" select t1.*,tem.FNumber as fempcode,tem.FName as fempname,tem.FNote as fempgroup,tic.FName as fgxname,
    	tem.FEmail as fgxcode,	uu.FGroupID,u3.FName AS FGroupName from t_userw t1 left join t_emp tem on t1.FName = tem.FName LEFT JOIN t_icitem tic ON tic.FNumber = tem.femail
    	LEFT JOIN
    	( select top 1 gp.FUserID ,MAX(gp.FGroupID) FGroupID from t_Group gp
    	LEFT JOIN t_User u2 on u2.FUserID = gp.FUserID WHERE
    	u2.FName = '{$Fname}' GROUP BY gp.FGroupID,gp.FUserID  ORDER BY gp.FGroupID desc
    	) uu on uu.FUserID = t1.FUserID
    	LEFT JOIN t_User u3 on uu.FGroupID = u3.FUserID
    	where t1.FName = '{$Fname}' and t1.FSID='{$FSID}' order by t1.FName ";
    	$res = SqlServerUtil::exec($this->SqlServer, $sql);
    	
    	if(count($res)>0 && $res){
    		return response()->json(Common::successResponse(200,'登录成功',$res));
    	}
    	return response()->json(Common::errorResponse(400,'用户名或密码不正确'));
    }
    
    /**
    * 聚一科技 ^_^
    * @date: 2020年9月17日
    * @author: lq
    * @version:App V2.0
    */
    public function getErpTableConfig(Request $request){
    	$key = $request->get('key');
    	$res = SqlServerUtil::exec($this->SqlServer, "SELECT * FROM TP_T_RepListTitle WHERE FRepKey ='{$key}' ORDER BY FRepIndex");
    	$temp = [];
    	if($key == 203 ){
    		foreach ($res as $key => &$value) {
    			if(isset($value['FRepFld'])  )
    			{
    				$value['FRepFld'] = strtolower($value['FRepFld']);
    			}
    		}
    	}
    	
    	returnData(0, '同步成功',$res);
    }
    
	/**
	 * 设置字段
	* 聚一科技 ^_^
	* @date: 2020年9月1日
	* @author: lq
	* @version:App V2.0
	*/
	public function getTableConfig(Request $request){
		$key = $request->get('key');
		$keywordStr='';
		if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
			$keyword = $request->keyword;
			$keywordStr=" and (FRepKey like '%{$keyword}%' or FRepCap like '%{$keyword}%'  or FRepFld like '%{$keyword}%' )";
		}
		
		$ishideStr='';
		$ishide = $request->ishide;
		if ($ishide === 0) {
			$ishideStr=" and FRepHide = '{$ishide}' ";
		}elseif($ishide === 1){
			$ishideStr=" and FRepHide = '{$ishide}' ";
		}
		
		$FRepPage  = $request->FRepPage??0 ; //这里0 -- 序时薄 ，1-单据
		//判断 单据 
		$billtype  = $request->billtype??0 ; 
		$db = "gz_RepListTitle"; 
		if($billtype == 1){
			$db = "gz_RepBillTitle";
			$FRepPage =1 ; 
		} 
		$res = SqlServerUtil::execTosql($this->SqlServer, "SELECT * FROM {$db} WHERE FRepKey ='{$key}' and  FRepPage = '{$FRepPage}' {$ishideStr} {$keywordStr}  ORDER BY FRepIndex");
			
		$temp = [];
		if($res){
		    $res = arraykeyToLower($res);
// 		    dd($res);
		    foreach ($res as $k=>$v)
		    {
		        $res[$k]['frepfld'] = strtolower($v['frepfld']);
		    }
		}
// 		foreach ($res as $key => $value) {
// 			array_push($temp, [
// 					'fid' => $value['FID'],
// 					'fuserid' => $value['FUserID'],
// 					'frepkey' => $value['FRepKey'],
// 					'frepindex' => $value['FRepIndex'],
// 					'freppage' => $value['FRepPage'],
// 					'frepcap' => $value['FRepCap'], //字段名称
// 					'frepfld' => $value['FRepFld'],//字段
// 					'freptype' => $value['FRepType'],
// 					'frephide' => $value['FRepHide'],
// 					'frepsum' => $value['FRepSum'],
// 					'frepwid' => $value['FRepWid'],
// 					'frightkey' => $value['FRightKey'],
// 					'frpttypeflag' => intval($value['FRptTypeFlag']),
// 					'fdecplaces' => $value['FDecPlaces'],
// 					'funcontrol' => $value['FUnControl'],
// 					'frepmeg' => $value['FRepMeg'],
// 					'frepcap_en' => $value['FRepCap_En'],
					
// 			]);
// 		}
		
		returnData(0, '同步成功',$res);
	}
	
	 
	
	/**
	* 聚一科技 ^_^
	* 参数修改
	* @date: 2020年9月1日
	* @author: lq
	* @version:App V2.0
	*/
	public function getConfigUpdate(Request $request){
		$fid = $request->fid;
		$param =$request->all();
		//判断 单据
		$billtype  = $request->billtype??0 ;
		$db = "gz_RepListTitle";
		if($billtype == 1){
			$db = "gz_RepBillTitle";
			unset($param['billtype']);
			 
		}
		if(empty($fid)){
			showMsg(1,'参数传值错误');
		}
		
		unset($param['fid']);
		unset($param['db']);
		$param = _unsetNull($param);
		
		$qkidupdate= SqlServerUtil::exeupdateTosql($this->SqlServer,$db,$param ,['FID'=>$fid]);
		if($qkidupdate){
			showMsg(0,'修改成功');
		}else{
			showMsg(1,'修改失败');
		}
	}
	
	/**
	* 聚一科技 ^_^
	*设置删除
	* @date: 2020年9月3日
	* @author: lq
	* @version:App V2.0
	*/
	public function getConfigDel(Request $request){
		$FItemID = $request ->get('fid');
		//判断 单据
		$billtype  = $request->billtype??0 ;
		$db = "gz_RepListTitle";
		if($billtype == 1){
			$db = "gz_RepBillTitle";
	 
			
		}
		
		$qkid = SqlServerUtil::sqlexec($this->SqlServer,"DELETE from {$db} WHERE FID= '{$FItemID}'");
		if($qkid){
			showMsg(200,'删除成功');
		}else{
			showMsg(400,'删除失败');
		}
		
	}
	
	/**
	* 聚一科技 ^_^
	* @date: 2020年9月1日
	* @author: lq
	* @version:App V2.0
	*/
	public function getConfigAdd(Request $request){
		$param =$request->all();
		$param = _unsetNull($param);
		$FRepPage  = $request->FRepPage??0 ; //这里0 -- 序时薄 ，1-单据 
		unset($param['db']);
		
		$qkidupdate= SqlServerUtil::sqlsrvCreateTosql($this->SqlServer,'gz_RepListTitle',$param );
		if($qkidupdate){
			showMsg(0,'新增成功');
		}else{
			showMsg(1,'新增失败');
		}
	}
	
	/**
	* 聚一科技 ^_^
	* 插表 --字段
	* @date: 2020年9月1日
	* @author: lq
	* @version:App V2.0
	*/
	public function insertColumn (Request $request){
		//FRepFld
		$column = $request->get('FRepFld');
		$FRepKey = $request->get('FRepKey'); 
		if(empty($FRepKey) || empty($column)){
			showMsg(1,'参数错误，请查看');
		}
		$db = columnBiao($FRepKey);
		$sql = "ALTER TABLE {$db} ADD {$column} nvarchar(200)  NULL DEFAULT ''";
		//$ins = SqlServerUtil::sqlexec($this->SqlServer, $sql);
		$ins = sqlsrv_query($this->SqlServer, $sql);
		if($ins){
			showMsg(0,'新增成功');
		}else{
			showMsg(1,'新增失败');
		}
	}
	
	/**
	* 聚一科技 ^_^
	* 文件保存
	* @date: 2020年9月2日
	* @author: lq
	* @version:App V2.0
	*/
	public function fileSave(Request $request){
		$gzsql  = $request->get('gzsql');
		$FRepKey  = $request->get('FRepKey');//对象代号
		
		$type =  $request->type??0 ; 
		
		if(empty($gzsql) || empty($FRepKey)){
			showMsg(1,'参数错误');
		}
		// 启动事务
		if (sqlsrv_begin_transaction($this->SqlServer) === false) {
			die(print_r(sqlsrv_errors(), true));
		}
		$delete =1;$is_success =1;
// 		$delete = sqlsrv_query($this->SqlServer,  "delete from gz_GZSQL where FRepKey='{$FRepKey}'");
// 		$is_success= SqlServerUtil::sqlsrvCreateTosql($this->SqlServer,'gz_GZSQL',['FRepKey'=>$FRepKey,'FSql'=>$gzsql] );
		if($type == 1){
			$is_success1 = saveFile("gzdata/{$FRepKey}_1.txt", $gzsql );
		}else{
			$is_success1 = saveFile("gzdata/{$FRepKey}.txt", $gzsql );
		}
	

		if($delete && $is_success){
			sqlsrv_commit($this->SqlServer);
			showMsg(0,'成功');
		}else{
			sqlsrv_rollback($this->SqlServer);
			showMsg(1,'失败');
		}
	}
	
	
	/**
	 * 
	* 聚一科技 ^_^
	* 获取通用文件
	* @date: 2020年9月2日
	* @author: lq
	* @version:App V2.0
	*/
	public function commonDataList(Request $request){
		$FRepKey  = $request->get('FRepKey');//对象代号
		if(empty($FRepKey)){
			showMsg(1,'对象代号不存在');
		}
		$page= $request ->get('page');
		if(!isset($page)) $page =1;
		$limit= $request ->get('limit');
		if(!isset($limit)) $limit =10;
		$pages = ($page-1)* $limit;
		$keywordStr='';
		$FRepPage  = $request->FRepPage??0 ; //这里0 -- 序时薄 ，1-单据
		
		
		
		if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
			$keyword = iconv('UTF-8','GBK',$request->keyword);
			$keywordStr=" and (v1.FNumber like '%{$keyword}%' or v1.FName like '%{$keyword}%' )";
		}
		
		$db = columnBiao($FRepKey);//表名
		$basesql="select * from gz_RepListTitle where FRepKey='{$FRepKey}' and FRepPage = '{$FRepPage}' and FRepHide =0 order by FRepIndex ";
		$baseData = SqlServerUtil::exec($this->SqlServer, $basesql );
		if($baseData){
			$baseData = arraykeyToLower($baseData);
		}
		//获取文件getfileSql
		$sqlData = getfileSql($FRepKey);
		if(!$sqlData){
			showMsg(1,'设置Sql不存在');
		}
		$sql=" select top $limit * from ( $sqlData ) temp_row where rownumber>(($page-1)*$limit)";
		
		$vowels = array("\n", "\r", "\t");
		$sql = str_replace($vowels, ' ',$sql);
		
		//做变量替换
		$sql = str_replace('{keyword}', $keywordStr, $sql);
		
		$sql = strtolower($sql);
		
		$res = SqlServerUtil::exec($this->SqlServer,$sql);
		if($res === false){
			showMsg(1,'设置Sql错误重新编辑！');
		}
		$result =[];
		if($res){
			$result = arraykeyToLower($res);
		}
	
		//showMsg(0,'成功',$result);
		$countSql ="SELECT COUNT(1) AS total FROM {$db} where 1=1 $keywordStr";
		$count = SqlServerUtil::exec($this->SqlServer, $countSql);
		$this->response['total'] = $count ? $count[0]['total']:0;
		$this->response['size'] = 1;
		$last_page =0;
		if($count && count($count)>0){
			$last_page = ceil($count[0]['total']/$limit);
			$this->response['size'] = $limit;
		}
		
		$this->response['Data'] = $res;
		$this->response['cur_page'] =$page;
		$this->response['last_page'] =$last_page;
		return response()->json($this->response);
	}
	
	public function getSql(Request $request){
		$FRepKey  = $request->get('FRepKey');//对象代号
		$type = $request->type??0 ;
		$sqlData = getfileSql($FRepKey , $type);
		// $sqlData = SqlServerUtil::exec($this->SqlServer, "select fsql from gz_GZSQL where FRepKey ='{$FRepKey}'" ,2);
		if(!$sqlData){
			showMsg(0,'设置Sql为空',[]);
		}
		showMsg(0,'成功',$sqlData);
		// showMsg(0,'成功',$sqlData['fsql']);
	}
	
	/**
	* 获取字段数据
	* @date: 2022年12月6日 上午10:00:07
	* @author: juyi
	*/
	public function getConfigColumn(Request $request){
	 
		$FRepKey = $request->get('FRepKey');
		if(strval($FRepKey) == '26024_1'){
			$FRepKey = '2602401' ; // 船检费(固定)
		}
	
		$FRepPage  = $request->FRepPage??0 ; //这里0 -- 序时薄 ，1-单据
		$opername = $request->get('opername'); //当前登录人名称 
		$opernameStr = '';
		$ConData =[];
		$fieldData = [];
		$removeData = [];
		
		//字段权限 查看
		//判断是否在系统管理员组
		$conSql ="SELECT  ad.username,g.fname  from gz_user_group ug
		left join  gz_admin ad   on ug.userid = ad.id
		left join gz_group g  on  g.id = ug.groupid
		where g.fname = '系统管理员组'  and  ad.username ='{$opername}' ";
		$ConData = SqlServerUtil::execToSql($this->SqlServer, $conSql );
		if(empty($ConData))
		{
			//不在 ，所在权限组 是否有权限查看
			$fieldSql ="SELECT  ad.username,g.fname ,fld.FFunc
			from gz_user_group ug
			left join  gz_admin ad   on ug.userid = ad.id
			left join gz_group g  on  g.id = ug.groupid
			left join gz_ObjectAccessField fld on fld.fgroupid = g.id
			where  ad.username ='{$opername}'";
			$fieldData = SqlServerUtil::execToSql($this->SqlServer, $fieldSql );
			$removeData = getFldViewDiff($fieldData);
		}
		
		//新增，修改 -- 显示 0 ，序时薄 ==0，1
		//FRptTypeFlag --序时薄显示0 ，1-隐藏
		//FUnControl -- 新增修改0 ，1-隐藏
		//FRepMeg -- 下拉框1 ,单选框2 ,多选框3 ,日期框4 ,禁止编辑5 , 多文本框6
		$FUnControlStr ='';
		$FUnControl  = $request->FUnControl??0;
		if ($FUnControl >  0   ) {
			$FUnControlStr=" and ( FUnControl =  {$FUnControl} )";
		}
		$basesql="select * from gz_RepListTitle where FRepKey= '{$FRepKey}' and FRepPage = '{$FRepPage}' and FRepHide = 0  {$FUnControlStr}  {$opernameStr} order by FRepIndex ";
// 		echo $basesql;die;
		$baseData = SqlServerUtil::execToSql($this->SqlServer, $basesql );
		if($baseData){
			$baseData = arraykeyToLower($baseData);
			foreach ($baseData as $k=>$v)
			{
				$baseData[$k]['frepfld'] = strtolower($v['frepfld']);
			}
		}
		 
		// 过滤权限
		if($removeData){
			foreach ($baseData as $k1=> $v1)
			{
				if(in_array($v1['frightkey'] ,$removeData)) {
					unset($baseData[$k1]);
				}
			}
			$baseData = array_values($baseData);
		}
		returnData(0, '成功',$baseData);
		
// 		$basesql="select * from gz_RepListTitle where FRepKey= '{$FRepKey}' and  FRepPage = '{$FRepPage}' and FRepHide =0 order by FRepIndex ";
// 		$baseData = SqlServerUtil::exec($this->SqlServer, $basesql );
// 		if($baseData){
// 			$baseData = arraykeyToLower($baseData);
// 			foreach ($baseData as $k=>$v)
// 			{
// 				$baseData[$k]['frepfld'] = strtolower($v['frepfld']); 
// 			}
// 		}
// 		returnData(0, '成功',$baseData);
	}

	/**
	* 聚一科技 ^_^
	* 用户列表
	* @date: 2020年9月2日
	* @author: lq
	* @version:App V2.0
	*/
	public function getUserList(Request $request){
		$param =$request->all();
		$param = _unsetNull($param);
		unset($param['db']);
		$qkidupdate= SqlServerUtil::sqlsrvCreateTosql($this->SqlServer,'gz_admin',$param );
		if($qkidupdate){
			showMsg(0,'新增成功');
		}else{
			showMsg(1,'新增失败');
		}
	}
	
	/**
	* 聚一科技 ^_^
	* 通用ADD up
	* @date: 2020年9月7日
	* @author: lq
	* @version:App V2.0
	*/
	public function genAdd(Request $request)
	{
		$FRepKey= $request->get('FRepKey');
		$db = columnBiao($FRepKey);//表名 
		$opername  = $request->opername?$request->opername:'' ;
		//职员代码 是否有值
		$param =$request->all();
		$resMX =[];
		//设置 值
		$getVexTableColumnData = $this->getVexTableColumn($FRepKey  ) ;
		$insData =[];
		foreach ($getVexTableColumnData as  $up)
		{
			if( ( empty($param[$up['frepfld']]) ||  $param[$up['frepfld']] =='.00' ) && $up['freptype'] == 131 ){
				$param[$up['frepfld']] =0;
			}
			if( empty($param[$up['frepfld']])  && ($up['freptype'] == 202 || $up['freptype'] == 200 ) ){
				$param[$up['frepfld']] = '';
			}
			$resMX[$up['frepfld']] = $param[$up['frepfld']];
			if(in_array($FRepKey,['26002','25002','25003','25004','25005','25002',])){
				$resMX['opername'] = $opername;
				$resMX['operType'] = '界面新增或修改';
			}
			if(in_array($FRepKey,['26015',])){
				$resMX['ffax'] = $param['ffax'] ;
			}
			
		}
		//船检费
		if(in_array($FRepKey,['26002'])){
			$CS =  $this->getSystemProfile(['FSetChuanjianCCS']);
			$resMX['fchanjianfeiccs']  = round(($resMX['fzjjianyanf'] + $resMX['fnoxpaifangf'] + $resMX['flvtuf'] + $resMX['fjizuojijiaf']	
					+ $resMX['fzhusuf'] +   $resMX['fjiaotongf'] +  $resMX['ftongxunf']  +  $resMX['fzhengshuf'])/$CS['fsetchuanjianccs'],2)   ;
		}
		if(in_array($FRepKey,['25002'])){
			$huilv = $this->getSystemProfile(['FSetHuiLv'   ]);
			$resMX['fexchangerate'] = 1;
			if($huilv){
				$resMX['fexchangerate'] = $huilv['fsethuilv'];
			}
			//整机检验费人民币
			$resMX['fzjjianyanfrmb'] =  round( $resMX['fzjjianyanf']*$resMX['fexchangerate'] ,2);
			//NOX排放费人民币
			$resMX['fnoxpaifangfrmb'] = round($resMX['fnoxpaifangf'] *$resMX['fexchangerate'] ,2) ;
			//证书费人民币
			$resMX['fzhengshufrmb'] =  round($resMX['fzhengshuf'] *$resMX['fexchangerate']*30 ,2);
			//旅途时间费用人民币
			$resMX['flvtufrmb'] =  round( $resMX['flvtuf'] *$resMX['fexchangerate'] ,2) ;
			//  船检费ABS
			$resMX['fchanjianfeiabs']  = round( $resMX['fzjjianyanfrmb'] + $resMX['fnoxpaifangfrmb'] + $resMX['fzhengshufrmb'] + $resMX['flvtufrmb'] + $resMX['fzhusufrmb'] + $resMX['franyoufrmb'] + $resMX['fguolufrmb']+  $resMX['fhuosibutiermb'] ,2)  ;
		}
		if(in_array($FRepKey,['25003'])){
			$resMX['fchanjianfeilr']  =round( $resMX['fzjjianyanf'] + $resMX['fnoxpaifangf'] + $resMX['flvtuf'] + $resMX['fjizuojijiaf'] + $resMX['fzhusuf'] + $resMX['fguoyejintie'] +  $resMX['franyouf'] + $resMX['fguoluf']+  $resMX['fzhengshuf'] ,2)   ;
		}
		if(in_array($FRepKey,['25004'])){
			$resMX['fchanjianfeibv']  = round($resMX['fzjjianyanf'] + $resMX['fnoxpaifangf'] + $resMX['flvtuf'] + $resMX['fjizuojijiaf'] + $resMX['fzhusuf']  +  $resMX['franyouf'] + $resMX['fguoluf']+  $resMX['fzhengshuf']  ,2)  ;
		}
		if(in_array($FRepKey,['25005'])){
			$resMX['fchanjianfeidnv']  = round($resMX['fzjjianyanf'] + $resMX['fnoxpaifangf'] + $resMX['flvtuf'] + $resMX['fjizuojijiaf'] + $resMX['fzhusuf'] +$resMX['fchuchaibutie'] +  $resMX['franyouf'] + $resMX['fguoluf'] +  $resMX['fzhengshuf']  ,2)  ;
		}
		
		//---录入 
		//运保费  26016
		if(in_array($FRepKey,['26016'  ])){
			$cs = $this->getSystemProfile(['FSetFFAX' ,'FSetTuZhiSS','FSetYunBaoF',   ]);
			$resMX['fbaoxianfei'] = $resMX['fsaleamount'] * $resMX['ffeilv'] ;
			$resMX['fyunshufei'] =  $resMX['fhailishu'] *  $resMX['fhailiprice']  ;
			$resMX['fallamount'] =  round($resMX['fbaoxianfei'] *(1+$cs['fsetffax']/100) / $cs['fsettuzhiss'] ,2)
			+  round(($resMX['fyunshufei']+  $resMX['fysguding'])*(1+$cs['fsetffax']/100) / $cs['fsetyunbaof'] ,2)    ;
		}
		//水电费  26011
		if(in_array($FRepKey,['26011'  ])){
			$resMX['fjgcjdwamount'] =  ($resMX['fjgcjdw']??0) * ($resMX['fjgcjdwprice']??0)  ;
			$resMX['fallamount'] =  ($resMX['fjgcjdwamount']??0) + ($resMX['fjijiacj']??0 ) + ($resMX['fzhuangshicj']??0 )  + ($resMX['fhanjiecj']??0 ) ;
		}
		//辅材成本   机加工-28006   ，装试-28007, 结构-26008
		if(in_array($FRepKey,['26008'  ])){
			$sql = "select  fbrand ,fmodel,fpower,fzzjweight,ffuliao as fdihao , fpackage as fbaozhuangwu,ffuliaopakeage  from gz_YBaseJS where fmodel = '{$resMX['fmodel']}' " ;
			$TempDataJS = SqlServerUtil::execToSql($this->SqlServer,$sql,2);
			if(empty($TempDataJS)){
				showMsg(400, '技术中心不存在这个机型，请确认');
			}
			
			$cs = $this->getSystemProfile([ 'FSetFuCaiDWPrice'   ]);
			$resMX['fzzjweight'] = $TempDataJS['fzzjweight'] ;
			$resMX['fdunweiprice'] = $cs['fsetfucaidwprice'];
			$resMX['fdunweicb']  =  ($resMX['fzzjweight']??0) *  $resMX['fdunweiprice'] ;
			$resMX['fallamount'] =  ($resMX['fzjyouqi']??0) + ($resMX['ftuihuocb']??0 ) + ($resMX['fqitaftcb']??0 ) + $resMX['fdunweicb']??0  ;
		}
		if($FRepKey == 28006){
			//合计    不需要分摊
			$CS = $this->getSystemProfile(['FSetProdFY'   ]);
			//生产部
			$ProdData =  SqlServerUtil::execToSql($this->SqlServer, " select  fdaojuxiaohao as fdaojufy, fmodel from gz_YBaseProduce  where fmodel = '{$resMX['fmodel']}'  ",2 );
			if(empty($ProdData)){
				showMsg(400,'生产部机型没有这个机型数据');
			}
			$resMX['fdaojufy'] =  $ProdData['fdaojufy'] ;
			$resMX['fallamount']  =  ($resMX['fdaojufy']*$CS['fsetprodfy']??0) + ($resMX['ffentanfy']??0)  ;
		}
		if($FRepKey == 28007){
			$sql = "select  fbrand ,fmodel,fpower,fzzjweight,ffuliao as fdihao , fpackage as fbaozhuangwu,ffuliaopakeage  from gz_YBaseJS where fmodel = '{$resMX['fmodel']}' " ;
			$TempDataJS = SqlServerUtil::execToSql($this->SqlServer,$sql,2);
			if(empty($TempDataJS)){
				showMsg(400, '技术中心不存在这个机型，请确认');
			} 
			$temjs280047 = $TempDataJS;
			$cs = $this->getSystemProfile([ 'FSetFFAX' ,'fsetfucai535value','fsetfucai550value','fsetfucaibzw535value',
					'fsetfucaibzw550value',]);
			if($temjs280047){
				if($temjs280047['ffuliaopakeage'] == '535'){
					$resMX['fdihao'] = $temjs280047['fdihao']* $cs['fsetfucai535value'] ;
					$resMX['fbaozhuangwu'] = $temjs280047['fbaozhuangwu']* $cs['fsetfucaibzw535value'] ;
				}
				if($temjs280047['ffuliaopakeage'] == '550'){
					$resMX['fdihao'] = $temjs280047['fdihao']* $cs['fsetfucai550value'];
					$resMX['fbaozhuangwu'] = $temjs280047['fbaozhuangwu']* $cs['fsetfucaibzw550value'] ;
				}
			}else{
				showMsg(400,'辅材数据对应机型不正确');
			}
			// 装试车间低耗和包装物系数是根据550或者535计算的
			$resMX['fallamount'] =  ($resMX['fdihao']??0) + ($resMX['fbaozhuangwu']??0 ) + ($resMX['fyoulvqi']??0 )
			+ ($resMX['fqitayoupin']??0) + ($resMX['ffentanfycj']??0 ) + ($resMX['ffentanfysczl']??0)  ;
			
		}
		//售后维护成本
		if($FRepKey == 26012){
			// 1.按照售后差旅+人工+材料；   ，，	一种是固定金额  fshguding
			//售后调试成本
			$resMX['fallamount'] =  ($resMX['fshcailiao']??0) + ($resMX['fshrengong']??0 ) + ($resMX['fshchailv']??0 )+($resMX['fshguding']??0)  ;
		}
		//质量成本
		if($FRepKey == 26013){
			// 1.按照售后差旅+人工+材料；   ，，	一种是固定金额 fzlguding
			//售后调试成本
			$resMX['fallamount'] =  ($resMX['fcaigouamount']??0) + ($resMX['fjishuamount']??0 )+ ($resMX['fzlguding']??0 )    ;
		}	
		//图纸
		if(in_array($FRepKey, [ '26015'  ])  ){
			//WINGD:第一次判断是否同样的机，有，为0;
			//没有，进行二次判断，判断是不是同样的机型不同的缸数， 有，则按照不同缸数收费，  无，就按照首台
			//MAN:第一次判断是否同样的机，有，按照不同应用型式；
			//没有，进行二次判断，判断是不是同样的机型不同的缸数， 有，则按照不同缸数收费；无，就按照首台。
			$tz = $this->getSystemProfile(['FSetHuiLv','FSetHuiLvFaLang','FSetHuiLvOyuan'   ]);
			$resMX['fexchangerate'] = strtoupper($resMX['fbrand']) == 'WINGD'?$tz['fsethuilvfalang']:$tz['fsethuilvoyuan'] ;
			$resMX['fallamount'] =  round($resMX['ftzfeiyong']* $resMX['fexchangerate'] ,2)   ;
			//图纸合计 含税
			$resMX['ffaxallamount']  = round((floatval($resMX['ftzfeiyong']*$resMX['fexchangerate'])  )*(1+$resMX['ffax']/100) ,2)  ;
		}
		
		//专利 
		if(in_array($FRepKey, [ '26004'  ])  ){
			$resMX['fPatentfeeAmount'] =  ($resMX['fexchangerate']??1) * ($resMX['fpatentfee']??0 ) ;
		}
		
		
// 		dd($resMX);
		//-- 新增 机型   FNumber ,FName
		if(!$request->input('fid')){
			if($request->input('fitemid') && $FRepKey ==12001){
				$FItemID = $param['fitemid'];
				unset($param['db']);
				unset($param['opername']);
				unset($param['FRepKey']);
				unset($param['fitemid']);
				$qkidupdate= SqlServerUtil::exeupdateTosql($this->SqlServer,$db,$param,['fitemid'=>$FItemID]);
				if($qkidupdate){
					$this->writeLog(getMkName($FRepKey),'修改' , $FRepKey , $param, $opername );
					showMsg(200,'修改成功');
				}else{
					showMsg(400,'修改失败');
				}
				
			}elseif($request->input('fitemid') && $FRepKey ==14002){
				$FItemID = $param['fitemid'];
				unset($param['db']);
				unset($param['opername']);
				unset($param['FRepKey']);
				unset($param['fitemid']);
		 
				$qkidupdate= SqlServerUtil::exeupdateTosql($this->SqlServer,$db,$param,['fitemid'=>$FItemID]);
				if($qkidupdate){
					$this->writeLog(getMkName($FRepKey),'修改' , $FRepKey , $param ,$opername);
					showMsg(200,'修改成功');
				}else{
					showMsg(400,'修改失败');
				}
				
			}elseif($request->input('fitemid') && $FRepKey ==14001){
				$FItemID = $param['fitemid'];
				unset($param['db']);
				unset($param['opername']);
				unset($param['FRepKey']);
				unset($param['fitemid']);
				
				$qkidupdate= SqlServerUtil::exeupdateTosql($this->SqlServer,$db,$param,['fitemid'=>$FItemID]);
				if($qkidupdate){
					$this->writeLog(getMkName($FRepKey),'修改' , $FRepKey , $param ,$opername );
					showMsg(200,'修改成功');
				}else{
					showMsg(400,'修改失败');
				}
			}
			
			switch ($FRepKey){
				//员工信息 
				case 12001:
					 
					unset($param['db']);
					unset($param['opername']);
					unset($param['FRepKey']);
					
					$qkid= SqlServerUtil::sqlsrvCreateTosql($this->SqlServer,$db,$param  );
					if($qkid){
						$this->writeLog(getMkName($FRepKey),'新增' , $FRepKey , $param ,$opername);
						showMsg(200,'保存成功');
					}else{
						showMsg(400,'保存失败');
					}
					break;

				case 14006:
					 
						unset($param['db']);
						unset($param['FRepKey']);
						unset($param['opername']);
						$qkid= SqlServerUtil::sqlsrvCreateTosql($this->SqlServer,$db,$param  );
						if($qkid){
							$this->writeLog(getMkName($FRepKey),'新增' , $FRepKey , $param  ,$opername);
							showMsg(200,'保存成功');
						}else{
							showMsg(400,'保存失败');
						}
						break;
					
					//参数设置
				case 14002:
					 
					unset($param['db']);
					unset($param['FRepKey']);
					unset($param['opername']);
					$qkid= SqlServerUtil::sqlsrvCreateTosql($this->SqlServer,$db,$param  );
					if($qkid){
						$this->writeLog(getMkName($FRepKey),'新增' , $FRepKey , $param  ,$opername);
						showMsg(200,'保存成功');
					}else{
						showMsg(400,'保存失败');
					}
					break;
					//参数设置
				case 14001:
					 
					unset($param['db']);
					unset($param['FRepKey']);
					unset($param['opername']);
					$param = array_filter(_unsetNull($param));
					$qkid= SqlServerUtil::sqlsrvCreateTosql($this->SqlServer,$db,$param  );
					if($qkid){
						$this->writeLog(getMkName($FRepKey),'新增' , $FRepKey , $param ,$opername );
						showMsg(200,'保存成功');
					}else{
						showMsg(400,'保存失败');
					}
					break;
			}
			
			if(in_array($FRepKey, ['12002','12005', '12225'  ])  ){
				$FYear = intval($param['fyear']);
				$FPeriod = intval($param['fperiod']);
				$param['fyear'] = $FYear;
				$param['fperiod'] = $FPeriod ;
				$FItemID = $param['fname'];
				
				$data = SqlServerUtil::exec($this->SqlServer, "select * from {$db} where FYear ='{$FYear}' and FPeriod ='{$FPeriod}' and FItemID ='{$FItemID}'",2);
				if($data) {showMsg(400,'本期间职员代号已存在');}
			}
			
			if($FRepKey =='12013'){
				if(!empty($param['ftsgz']) && $param['ftsgz']>0){
					$param['fjsamount']=$param['ftsgz'];
					$param['fgongshi'] = 0;
					$param['fjsgz'] = 0;
				}else{
					if(empty($param['fgongshi'])){
						$param['fgongshi'] = 1;
					}
					$param['fjsamount']= $param['fgongshi'] * $param['fjsgz'] ;
				}
			}
			
			if($FRepKey =='13002' || $FRepKey =='12020' ){
				unset($param['db']);
				unset($param['opername']);
				unset($param['FRepKey']);
				unset($param['fyear']);
				unset($param['fperiod']);
				$FItemID =0;
		
			}else{
				 // --- 新增
 				if(in_array($FRepKey, ['12002','12005', '12225' ])){
					unset($param['fname']);
				}
				unset($param['db']);
				unset($param['opername']);
				unset($param['FRepKey']);
				//26001-- 直接人工费 新增
				if($FRepKey == 26001 ){
					//人工费合计含税
					$param['ffaxallamount']  = (floatval($param['fhanjiecj']) * $param['fhanjieprice'] + floatval($param['fjijiacj']) * $param['fjijiaprice'] + floatval($param['fzhuangshicj']) * $param['fzhuangshiprice'] ) *(1+ $param['ffax']/100 )  ;
					//人工费合计  
					$param['fallamount']  = floatval($param['fhanjiecj']) * $param['fhanjieprice'] + floatval($param['fjijiacj']) * $param['fjijiaprice'] + floatval($param['fzhuangshicj']) * $param['fzhuangshiprice'] ;
					//总工时
					$param['fgongshi']  = floatval($param['fhanjiecj']) + floatval($param['fjijiacj']) + floatval($param['fzhuangshicj'])  ;
					
				}
				
				//船检费 26002  --新增
				//26002 -- 船检费CCS  /1.06
				if($FRepKey == 26002 ){
					$tt =  SqlServerUtil::execToSql($this->SqlServer, " select fbrand,fpower,fmodel from gz_YBaseJS where fmodel = '{$param['fmodel']}' ",2);
					if(empty($tt)){
						showMsg(400,'技术中心没有这个机型，请查看');
					}
					if($tt['fmodel'] !== $param['fmodel']){
						showMsg(400,'技术中心机型:'.$tt['fmodel'].' ，请检查（区分大小写）');
					}
					//本身是否存在该机型
					$ben =  SqlServerUtil::execToSql($this->SqlServer, " select  fmodel from {$db} where fmodel = '{$param['fmodel']}' ",2);
					if(!empty($ben)){
						showMsg(400,'该机型已存在无法新增，请查看');
					}
					
					$CS = $this->getSystemProfile(['FSetChuanjianCCS'   ]);
					// fzztax 增值税
					$param['fzztaxamount'] = round(($param['fzjjianyanf'] + $param['fnoxpaifangf'] + $param['flvtuf'] + $param['fjizuojijiaf'] + $param['fzhusuf'] + $param['fjiaotongf'] +  $param['ftongxunf']  +  $param['fzhengshuf'] ) * ($param['fzzfax']/100) ,2) ;
					
					// fallamount 金额
					$param['fallamount']  = $param['fzztaxamount']+ $param['fzjjianyanf'] + $param['fnoxpaifangf'] + $param['flvtuf'] + $param['fjizuojijiaf']	+ $param['fzhusuf'] + $param['fjiaotongf'] +  $param['ftongxunf'] +  $param['fzhengshuf']  + $param['fpaifangtestf']  ;
					$param['fchanjianfeiccs']  = round(($param['fzjjianyanf'] + $param['fnoxpaifangf'] + $param['flvtuf'] + $param['fjizuojijiaf']	+ $param['fzhusuf'] +   $param['fjiaotongf']
							+  $param['ftongxunf']  +  $param['fzhengshuf'])/$CS['fsetchuanjianccs'],2)   ;
					
				}
				//25002 -- 船检费ABS
				if($FRepKey == 25002 ){
					$tt =  SqlServerUtil::execToSql($this->SqlServer, " select fbrand,fpower,fmodel from gz_YBaseJS where fmodel = '{$param['fmodel']}' ",2);
					if(empty($tt)){
						showMsg(400,'技术中心没有这个机型，请查看');
					}
					if($tt['fmodel'] !== $param['fmodel']){
						showMsg(400,'技术中心机型:'.$tt['fmodel'].' ，请检查（区分大小写）');
					}
					//本身是否存在该机型
					$ben =  SqlServerUtil::execToSql($this->SqlServer, " select  fmodel from {$db} where fmodel = '{$param['fmodel']}' ",2);
					if(!empty($ben)){
						showMsg(400,'该机型已存在无法新增，请查看');
					}
					
					$huilv = $this->getSystemProfile(['FSetHuiLv'   ]);
					$param['fexchangerate'] = 1;
					if($huilv){
						$param['fexchangerate'] = $huilv['fsethuilv'];
					}
					//整机检验费人民币
					$param['fzjjianyanfrmb'] =  round( $param['fzjjianyanf']*$param['fexchangerate'] ,2);
					//NOX排放费人民币
					$param['fnoxpaifangfrmb'] = round($param['fnoxpaifangf'] *$param['fexchangerate'] ,2) ;
					//证书费人民币
					$param['fzhengshufrmb'] =  round($param['fzhengshuf'] *$param['fexchangerate'] ,2);
					//旅途时间费用人民币
					$param['flvtufrmb'] =  round( $param['flvtuf'] *$param['fexchangerate']*30 ,2) ;
					// fzztax 增值税
					$param['fzztaxamount'] = ($param['fzjjianyanfrmb'] + $param['fnoxpaifangfrmb'] + $param['fzhengshufrmb'] + $param['flvtufrmb'] + $param['fzhusufrmb'] + $param['franyoufrmb'] + $param['fguolufrmb']+  $param['fhuosibutiermb']   ) * ($param['fzzfax']/100)  ;
					
					// fallamount 金额
					$param['fallamount']  = $param['fzztaxamount'] + $param['fzjjianyanfrmb'] + $param['fnoxpaifangfrmb'] + $param['fzhengshufrmb'] + $param['flvtufrmb'] + $param['fzhusufrmb']  +  $param['franyoufrmb'] + $param['fguolufrmb']+  $param['fhuosibutiermb']+  $param['fpaifangtestfrmb']   ;
					//  船检费ABS
					$param['fchanjianfeiabs']  =  $param['fzjjianyanfrmb'] + $param['fnoxpaifangfrmb'] + $param['fzhengshufrmb'] + $param['flvtufrmb'] + $param['fzhusufrmb'] + $param['franyoufrmb'] + $param['fguolufrmb']+  $param['fhuosibutiermb']   ;
					
				}
				//船检费LR
				if($FRepKey == 25003 ){
					$tt =  SqlServerUtil::execToSql($this->SqlServer, " select fbrand,fpower,fmodel from gz_YBaseJS where fmodel = '{$param['fmodel']}' ",2);
					if(empty($tt)){
						showMsg(400,'技术中心没有这个机型，请查看');
					}
					if($tt['fmodel'] !== $param['fmodel']){
						showMsg(400,'技术中心机型:'.$tt['fmodel'].' ，请检查（区分大小写）');
					}
					//本身是否存在该机型
					$ben =  SqlServerUtil::execToSql($this->SqlServer, " select  fmodel from {$db} where fmodel = '{$param['fmodel']}' ",2);
					if(!empty($ben)){
						showMsg(400,'该机型已存在无法新增，请查看');
					}
					// fzztax 增值税
					$param['fzztaxamount'] = ($param['fzjjianyanf'] + $param['fnoxpaifangf'] + $param['flvtuf'] + $param['fjizuojijiaf'] + $param['fzhusuf'] + $param['fguoyejintie'] +  $param['franyouf'] + $param['fguoluf']+  $param['fzhengshuf']  ) * ($param['fzzfax']/100)  ;
					
					// fallamount 金额
					$param['fallamount']  = $param['fzztaxamount'] +$param['fzjjianyanf'] + $param['fnoxpaifangf'] + $param['flvtuf'] + $param['fjizuojijiaf']	+ $param['fzhusuf'] + $param['fguoyejintie'] +  $param['franyouf'] + $param['fguoluf']+  $param['fzhengshuf']+  $param['fpaifangtestf']   ;
					$param['fchanjianfeilr']  = $param['fzjjianyanf'] + $param['fnoxpaifangf'] + $param['flvtuf'] + $param['fjizuojijiaf'] + $param['fzhusuf'] + $param['fguoyejintie'] +  $param['franyouf'] + $param['fguoluf']+  $param['fzhengshuf']    ;
					
				}
				//船检费BV
				if($FRepKey == 25004 ){
					$tt =  SqlServerUtil::execToSql($this->SqlServer, " select fbrand,fpower,fmodel from gz_YBaseJS where fmodel = '{$param['fmodel']}' ",2);
					if(empty($tt)){
						showMsg(400,'技术中心没有这个机型，请查看');
					}
					if($tt['fmodel'] !== $param['fmodel']){
						showMsg(400,'技术中心机型:'.$tt['fmodel'].' ，请检查（区分大小写）');
					}
					//本身是否存在该机型
					$ben =  SqlServerUtil::execToSql($this->SqlServer, " select  fmodel from {$db} where fmodel = '{$param['fmodel']}' ",2);
					if(!empty($ben)){
						showMsg(400,'该机型已存在无法新增，请查看');
					}
					
					// fzztax 增值税
					$param['fzztaxamount'] = ($param['fzjjianyanf'] + $param['fnoxpaifangf'] + $param['flvtuf'] + $param['fjizuojijiaf'] + $param['fzhusuf']  +  $param['franyouf'] + $param['fguoluf']+  $param['fzhengshuf']   ) * ($param['fzzfax']/100)  ;
					
					// fallamount 金额
					$param['fallamount']  = $param['fzztaxamount'] +$param['fzjjianyanf'] + $param['fnoxpaifangf'] + $param['flvtuf'] + $param['fjizuojijiaf']	+ $param['fzhusuf']  +  $param['franyouf'] + $param['fguoluf']+  $param['fzhengshuf']+  $param['fpaifangtestf']   ;
					$param['fchanjianfeibv']  = $param['fzjjianyanf'] + $param['fnoxpaifangf'] + $param['flvtuf'] + $param['fjizuojijiaf'] + $param['fzhusuf']  +  $param['franyouf'] + $param['fguoluf']+  $param['fzhengshuf']    ;
					
				}
				//船检费DNV
				if($FRepKey == 25005 ){
					$tt =  SqlServerUtil::execToSql($this->SqlServer, " select fbrand,fpower,fmodel from gz_YBaseJS where fmodel = '{$param['fmodel']}' ",2);
					if(empty($tt)){
						showMsg(400,'技术中心没有这个机型，请查看');
					}
					if($tt['fmodel'] !== $param['fmodel']){
						showMsg(400,'技术中心机型:'.$tt['fmodel'].' ，请检查（区分大小写）');
					}
					//本身是否存在该机型
					$ben =  SqlServerUtil::execToSql($this->SqlServer, " select  fmodel from {$db} where fmodel = '{$param['fmodel']}' ",2);
					if(!empty($ben)){
						showMsg(400,'该机型已存在无法新增，请查看');
					}
					// fzztax 增值税
					$param['fzztaxamount'] = ($param['fzjjianyanf'] + $param['fnoxpaifangf'] + $param['flvtuf'] + $param['fjizuojijiaf'] + $param['fzhusuf']+$param['fchuchaibutie']  +  $param['franyouf']+ $param['fguoluf'] +  $param['fzhengshuf']   ) * ($param['fzzfax']/100)  ;
					
					// fallamount 金额
					$param['fallamount']  = $param['fzztaxamount'] +$param['fzjjianyanf'] + $param['fnoxpaifangf'] + $param['flvtuf'] + $param['fjizuojijiaf']	+ $param['fzhusuf']+$param['fchuchaibutie'] + $param['fguoluf'] +  $param['franyouf']  +  $param['fzhengshuf']+  $param['fpaifangtestf']   ;
					$param['fchanjianfeidnv']  = $param['fzjjianyanf'] + $param['fnoxpaifangf'] + $param['flvtuf'] + $param['fjizuojijiaf'] + $param['fzhusuf'] +$param['fchuchaibutie'] +  $param['franyouf'] + $param['fguoluf'] +  $param['fzhengshuf']    ;
					
				}
				
				//船检费 固定
				if($FRepKey == 26024 ){
					if($param['ftype'] != 'ABS'){
						//有汇率
						$param['fexchangerate'] = 1 ;
					}
					$param['fzjjianyanf'] = $param['fzjjianyanf'] ;
					$param['fzhengshuf']  = $param['fzhengshuf'] ;
					$param['flutuf'] = $param['flutuf'] ;
					$param['fpaifangmuxing'] = $param['fpaifangmuxing'] ;
					$param['fpaifangzixing'] = $param['fpaifangzixing'] ;
					// 证书费 + 路途费用  =  确定部分
					$param['fquedingbf'] = ($param['fzhengshuf'] + $param['flutuf']) * $param['fexchangerate'] ;
					// fallamount 金额
					$param['fallamount'] = ($param['fzjjianyanf'] + $param['fzhengshuf'] + $param['flutuf'] + $param['fpaifangmuxing'] + $param['fpaifangzixing']) * $param['fexchangerate'];
				}
				
				
				//气油费 --新增
				if($FRepKey == 26003 || $FRepKey == 26007  || $FRepKey == 26021 ){
					
					//气缸油单价*1.058
					$param['fcylinderoilprice'] =  ($param['fcylinderoilprice']??0)   ;
					//油 气  合计
					$param['fAllamount'] = (($param['fdieseloilqty']??0) * ($param['fprice']??0)) + (($param['fcylinderoil']??0) * $param['fcylinderoilprice']) + (($param['fmainoil']??0) * $param['fmainoilprice']) + (($param['fgasqty']??0) * ($param['fgasprice']??0 ) );
				}
				//专利合计--新增
				if($FRepKey == 26004){
					
					$param['fPatentfeeAmount'] =  ($param['fexchangerate']??1) * ($param['fpatentfee']??0 ) ;
				}
				//清单费
				if($FRepKey == 26005){
					$param['famount'] =  ($param['fprice']??0) * ($param['fqty']??0 ) ;
				}
				
				//辅材成本 26008 结构
				if($FRepKey == 26008){  // 暂时
					$js =  SqlServerUtil::execToSql($this->SqlServer, " select fbrand,fpower,fmodel from gz_YBaseJS where fmodel = '{$param['fmodel']}' ",2);
					if(empty($js)){
						showMsg(400,'技术中心没有这个机型，请查看');
					}
					if($js['fmodel'] !== $param['fmodel']){
						showMsg(400,'技术中心机型:'.$js['fmodel'].' ，请检查（区分大小写）');
					}
					//本身是否存在该机型
					$ben =  SqlServerUtil::execToSql($this->SqlServer, " select  fmodel from {$db} where fmodel = '{$param['fmodel']}' ",2);
					if(!empty($ben)){
						showMsg(400,'该机型已存在无法新增，请查看');
					}
					
					// 结构车间-制造费用表  用技术中心的自制件重量引过来
					// 按吨位计算的成本 fdunweicb  = 根据单价 乘以 吨位    这里 还差一个 吨位计算成本
					$tt =  SqlServerUtil::execToSql($this->SqlServer, " select fbrand,fpower,fzzjweight  from gz_YBaseJS where fmodel = '{$param['fmodel']}' ",2);
					$param['fzzjweight'] = 0;
					if(!empty($tt)){
						$param['fzzjweight'] = $tt['fzzjweight'];
					}
					
					$param['fdunweicb']  =  ($param['fzzjweight']??0) *  $param['fdunweiprice'] ;
					$param['fallamount'] =  ($param['fzjyouqi']??0) + ($param['ftuihuocb']??0 ) + ($param['fqitaftcb']??0 ) + $param['fdunweicb']??0  ;
				}
				
				//辅材成本 28006  -- 机加工
				if($FRepKey == 28006){
					$js =  SqlServerUtil::execToSql($this->SqlServer, " select fbrand,fpower,fmodel from gz_YBaseJS where fmodel = '{$param['fmodel']}' ",2);
					if(empty($js)){
						showMsg(400,'技术中心没有这个机型，请查看');
					}
					if($js['fmodel'] !== $param['fmodel']){
						showMsg(400,'技术中心机型:'.$js['fmodel'].' ，请检查（区分大小写）');
					}
					//本身是否存在该机型
					$ben =  SqlServerUtil::execToSql($this->SqlServer, " select  fmodel from {$db} where fmodel = '{$param['fmodel']}' ",2);
					if(!empty($ben)){
						showMsg(400,'该机型已存在无法新增，请查看');
					}
					
					$tt =  SqlServerUtil::execToSql($this->SqlServer, " select  fdaojuxiaohao as fdaojufy from gz_YBaseProduce  where fmodel = '{$param['fmodel']}' ",2);
					$param['fdaojufy'] = 0;
					if(!empty($tt)){
						$param['fdaojufy'] = $tt['fdaojufy'];
					}
					$CS = $this->getSystemProfile(['FSetProdFY'   ]);
					//合计    不需要分摊  
					$param['fallamount']  =  ($param['fdaojufy']*$CS['fsetprodfy']??0) + ($param['ffentanfy']??0)  ;
				}
				
				//辅材成本 28007 -- 装试
				if($FRepKey == 28007){
					$js =  SqlServerUtil::execToSql($this->SqlServer, " select fbrand,fpower,fmodel from gz_YBaseJS where fmodel = '{$param['fmodel']}' ",2);
					if(empty($js)){
						showMsg(400,'技术中心没有这个机型，请查看');
					}
					if($js['fmodel'] !== $param['fmodel']){
						showMsg(400,'技术中心机型:'.$js['fmodel'].' ，请检查（区分大小写）');
					}
					//本身是否存在该机型
					$ben =  SqlServerUtil::execToSql($this->SqlServer, " select  fmodel from {$db} where fmodel = '{$param['fmodel']}' ",2);
					if(!empty($ben)){
						showMsg(400,'该机型已存在无法新增，请查看');
					}
					 
					// 低耗	包装物  带过来 * 10000
					$tt =  SqlServerUtil::execToSql($this->SqlServer, " select  ffuliao as fdihao , fpackage as fbaozhuangwu,ffuliaopakeage  from gz_YBaseJS  where fmodel = '{$param['fmodel']}' ",2);
					
					$param['fdihao'] = 0;
					$param['fbaozhuangwu'] = 0;
					$yy = $this->getSystemProfile(['fsetfucai535value','fsetfucai550value','fsetfucaibzw535value','fsetfucaibzw550value']);
					$fsetfucaibzw550value = 0 ;
					$fsetfucai550value =0 ;
					$fsetfucaibzw535value = 0 ;
					$fsetfucai535value = 0 ;
					if(!empty($yy)){
						$fsetfucaibzw550value = $yy['fsetfucaibzw550value'] ;
						$fsetfucai550value = $yy['fsetfucai550value'] ;
						
						$fsetfucaibzw535value = $yy['fsetfucaibzw535value'] ;
						$fsetfucai535value = $yy['fsetfucai535value'] ;
					}
					if(!empty($tt)){
						if($tt['ffuliaopakeage'] == '535'){
							$param['fdihao'] = $tt['fdihao']* $fsetfucai535value ;
							$param['fbaozhuangwu'] = $tt['fbaozhuangwu']* $fsetfucaibzw535value ;
						}
						if($tt['ffuliaopakeage'] == '550'){
							$param['fdihao'] = $tt['fdihao']* $fsetfucai550value ;
							$param['fbaozhuangwu'] = $tt['fbaozhuangwu']* $fsetfucaibzw550value ;
						}
					}
					// 装试车间低耗和包装物系数是根据550或者535计算的
					$param['fallamount'] =  ($param['fdihao']??0) + ($param['fbaozhuangwu']??0 ) + ($param['fyoulvqi']??0 ) + ($param['fqitayoupin']??0)  + ($param['ffentanfycj']??0 ) + ($param['ffentanfysczl']??0)  ;
				}
				
				//采购成本 26009
				if($FRepKey == 26009 || $FRepKey == 26022 ){
					$param['fnotfaxamount'] =  ($param['fnotfaxamount']??0)  ;
					$param['ffaxamount'] =  ($param['fnotfaxamount']??0) *(1+$param['ffax']/100) ;
				}
				
				
				
				// 折旧费  26010  折旧用各车间折旧总金额/台数
				if($FRepKey == 26010){
					$param['fhanjiecjzj'] = round( ($param['fhanjiecj']??0) /($param['fjijiaqty']??1),2)  ;
					$param['fjijiacjzj'] =   round( ($param['fjijiacj']??0 ) /($param['fjijiaqty']??1),2)  ;
					$param['fzhuangshicjzj'] =   round( ($param['fzhuangshicj']??0 )/($param['fjijiaqty']??1),2)   ;
					
					$param['fcjzjamount'] =  ($param['fhanjiecjzj']??0) + ($param['fjijiacjzj']??0 ) + ($param['fzhuangshicjzj']??0 ) ;
				}
				
				
				//水电合计 26011
				if($FRepKey == 26011){
					$js =  SqlServerUtil::execToSql($this->SqlServer, " select fbrand,fpower,fmodel from gz_YBaseJS where fmodel = '{$param['fmodel']}' ",2);
					if(empty($js)){
						showMsg(400,'技术中心没有这个机型，请查看');
					}
					if($js['fmodel'] !== $param['fmodel']){
						showMsg(400,'技术中心机型:'.$js['fmodel'].' ，请检查（区分大小写）');
					}
					//本身是否存在该机型
					$ben =  SqlServerUtil::execToSql($this->SqlServer, " select  fmodel from {$db} where fmodel = '{$param['fmodel']}' ",2);
					if(!empty($ben)){
						showMsg(400,'该机型已存在无法新增，请查看');
					}
					// 结构车间水电费  : 一种是按照吨位计算，即吨位单价乘以吨位；  一种是固定金额 fhanjiecj
					// 结构车间吨位	fjgcjdw  -- 技术中心  ，，  自制件重量
					// 结构车间吨位单价	fjgcjdwprice   -- 参数获取
					$param['fjgcjdw'] = 0 ;
					$param['fjgcjdwprice'] = 0;
					$sd = $this->getSystemProfile(['FSetShuiDianjgcjPrice'   ]);
					if($sd){
						$param['fjgcjdwprice'] = empty($sd['fsetshuidianjgcjprice'])?0:$sd['fsetshuidianjgcjprice'];
					}
					$tt =  SqlServerUtil::execToSql($this->SqlServer, " select   fzzjweight    from gz_YBaseJS  where fmodel = '{$param['fmodel']}' ",2);
					if($tt){
						$param['fjgcjdw'] = $tt['fzzjweight'];
					}
					// 结构车间金额	fjgcjdwamount
					$param['fjgcjdwamount'] =  ($param['fjgcjdw']??0) * ($param['fjgcjdwprice']??0)  ;
					//水电费合计
					$param['fallamount'] =  ($param['fjgcjdwamount']??0) + ($param['fjijiacj']??0 ) + ($param['fzhuangshicj']??0 )  + ($param['fhanjiecj']??0 ) ;
					//水电费合计 含税
					$param['ffaxallamount']  = (floatval($param['fjgcjdwamount'])  + floatval($param['fjijiacj'])  + floatval($param['fzhuangshicj']) + ($param['fhanjiecj']??0 ))*(1+$param['ffax']/100)   ;
				}
				
				//售后调试成本  26012
				if($FRepKey == 26012){
					$js =  SqlServerUtil::execToSql($this->SqlServer, " select fbrand,fpower,fmodel from gz_YBaseJS where fmodel = '{$param['fmodel']}' ",2);
					if(empty($js)){
						showMsg(400,'技术中心没有这个机型，请查看');
					}
					if($js['fmodel'] !== $param['fmodel']){
						showMsg(400,'技术中心机型:'.$js['fmodel'].' ，请检查（区分大小写）');
					}
					//本身是否存在该机型
					$ben =  SqlServerUtil::execToSql($this->SqlServer, " select  fmodel from {$db} where fmodel = '{$param['fmodel']}' ",2);
					if(!empty($ben)){
						showMsg(400,'该机型已存在无法新增，请查看');
					}
					// 1.按照售后差旅+人工+材料；   ，，	一种是固定金额  fshguding
					//售后调试成本
					$param['fallamount'] =  ($param['fshcailiao']??0) + ($param['fshrengong']??0 ) + ($param['fshchailv']??0 )+($param['fshguding']??0)  ;
					//售后调试成本  含税 
					$param['ffaxallamount']  = (($param['fshcailiao']??0) + ($param['fshrengong']??0 ) + ($param['fshchailv']??0 )+ ($param['fshguding']??0) )*(1+$param['ffax']/100)   ;
				}
				
				// 质量成本  26013
				if($FRepKey == 26013){
					$js =  SqlServerUtil::execToSql($this->SqlServer, " select fbrand,fpower,fmodel from gz_YBaseJS where fmodel = '{$param['fmodel']}' ",2);
					if(empty($js)){
						showMsg(400,'技术中心没有这个机型，请查看');
					}
					if($js['fmodel'] !== $param['fmodel']){
						showMsg(400,'技术中心机型:'.$js['fmodel'].' ，请检查（区分大小写）');
					}
					//本身是否存在该机型
					$ben =  SqlServerUtil::execToSql($this->SqlServer, " select  fmodel from {$db} where fmodel = '{$param['fmodel']}' ",2);
					if(!empty($ben)){
						showMsg(400,'该机型已存在无法新增，请查看');
					}
					
					// 1.按照售后差旅+人工+材料；   ，，	一种是固定金额 fzlguding
// 					$param['fallamount'] =  ($param['fzlguding']??0)  ;
					//售后调试成本
					$param['fallamount'] =  ($param['fcaigouamount']??0) + ($param['fjishuamount']??0 )+($param['fzlguding']??0)    ;
					//售后调试成本  含税
					$param['ffaxallamount']  = ( ($param['fcaigouamount']??0) + ($param['fjishuamount']??0 ) +($param['fzlguding']??0)   )*(1+$param['ffax']/100)   ;
					 
				}
				
				//委外费用 26014
				if($FRepKey == 26014){
					//委外费用合计
					$param['fallamount']= $param['fjuanyuan'] + $param['flingxingjg']+ $param['fsuanxi']+ $param['fjizuo']+ $param['fjijia']
					+ $param['fqita']+ $param['fpaiyanguan']+ $param['fzoutai']+ $param['fgzfentan']+ $param['fpaiyanguanbgr']+ $param['fjinqixiang']+ $param['fzjguan']   ;
					
					//委外费用合计 含税
					$param['ffaxallamount']  = ($param['fjuanyuan'] + $param['flingxingjg']+ $param['fsuanxi']+ $param['fjizuo']+ $param['fjijia']
							+ $param['fqita']+ $param['fpaiyanguan']+ $param['fzoutai']+ $param['fgzfentan']+ $param['fpaiyanguanbgr']+ $param['fjinqixiang']+ $param['fzjguan'] )*(1+$param['ffax']/100)   ;
				}
				
				//图纸费 26015
				if(in_array($FRepKey, [ '26015'  ])  ){// 暂时
					//WINGD:第一次判断是否同样的机，有，为0;
					//没有，进行二次判断，判断是不是同样的机型不同的缸数， 有，则按照不同缸数收费，  无，就按照首台
					//MAN:第一次判断是否同样的机，有，按照不同应用型式；
					//没有，进行二次判断，判断是不是同样的机型不同的缸数， 有，则按照不同缸数收费；无，就按照首台。
					$tz = $this->getSystemProfile(['FSetHuiLv','FSetHuiLvFaLang','FSetHuiLvOyuan'   ]);
					$param['fexchangerate'] = strtoupper($param['fbrand']) == 'WINGD'?$tz['fsethuilvfalang']:$tz['fsethuilvoyuan'] ;
					$param['fallamount'] =  round($param['ftzfeiyong']* $param['fexchangerate'] ,2)   ;
					//图纸合计 含税
					$param['ffaxallamount']  = round((floatval($param['ftzfeiyong']*$param['fexchangerate'])  )*(1+$param['ffax']/100) ,2)  ;
				}
				
				//运保费 26016
				if(in_array($FRepKey, [ '26016'  ])  ){
					$js =  SqlServerUtil::execToSql($this->SqlServer, " select fbrand,fpower,fmodel from gz_YBaseJS where fmodel = '{$param['fmodel']}' ",2);
					if(empty($js)){
						showMsg(400,'技术中心没有这个机型，请查看');
					}
					if($js['fmodel'] !== $param['fmodel']){
						showMsg(400,'技术中心机型:'.$js['fmodel'].' ，请检查（区分大小写）');
					}
					//本身是否存在该机型
					$ben =  SqlServerUtil::execToSql($this->SqlServer, " select  fmodel from {$db} where fmodel = '{$param['fmodel']}' ",2);
					if(!empty($ben)){
						showMsg(400,'该机型已存在无法新增，请查看');
					}
					//1.保险费： 用销售金额乘以费率 *（1+增值税率） / 1.06
					//2.运输费。运输地点，海里数，单位海里价格  * 1.13 /1.09
					$param['fbaoxianfei'] = $param['fsaleamount'] * ($param['ffeilv']??0)  ;
					
					$param['fyunshufei'] =  $param['fhailishu'] *  $param['fhailiprice']  ;
					$CS =  $this->getSystemProfile(['FSetTuZhiSS','FSetYunBaoF']);
					//$param['fallamount'] =  ($param['fysguding']??0)  ;
					//运保费合计
					$param['fallamount'] =  round($param['fbaoxianfei'] *(1+$param['ffax']/100) / $CS['fsettuzhiss'] ,2) 
					+  round(($param['fyunshufei']+  $param['fysguding'])*(1+$param['ffax']/100) / $CS['fsetyunbaof'],2)    ;
					//运保费合计 含税
					//$param['ffaxallamount']  =  round($param['fbaoxianfei'] *(1+$param['ffax']/100) / 1.06 ,2) +  round($param['fyunshufei']*(1+$param['ffax']/100) / 1.09,2)    ;
					
				}
				
				//特定工装 26017
				if(in_array($FRepKey, [ '26017'  ])  ){
					// 特定工装  整体发运 合计 
					// 整体发运  前面五项/分摊的台数+第六项  
					$param['fztfyAmount'] = round( ($param['fzjguan']+$param['fhanjiegz']+$param['fjijiagz'] + $param['fzhuangshigz']+$param['fshichegz'])/( empty($param['ffentantaishu'])?1:$param['ffentantaishu'] ) ,2)+$param['ffayungzzj']    ;
					// 分体发运 合计   2.前面五项/分摊的台数+第七项
					$param['fftfyAmount'] = round( ($param['fzjguan']+$param['fhanjiegz']+$param['fjijiagz'] + $param['fzhuangshigz']+$param['fshichegz']) /( empty($param['ffentantaishu'])?1:$param['ffentantaishu'] ) ,2) +$param['ffayungzfd']    ;
					
				}
				 
				//特定刀具 26018 
				if(in_array($FRepKey, [ '26018'  ])  ){
					// 用特殊刀具/分摊的台数
					$param['fallamount'] = round( (($param['fxjxtsdaoju']??0) +($param['fdjuxiaohao']??0) ) /( empty($param['ffentantaishu'])?1:$param['ffentantaishu'] ),2) ;
					//运保费合计 含税
					$param['ffaxallamount']  = round( (($param['fxjxtsdaoju']??0) +($param['fdjuxiaohao']??0) ) /( empty($param['ffentantaishu'])?1:$param['ffentantaishu'] )( empty($param['ffentantaishu'])?1:$param['ffentantaishu'] ) *(1+$param['ffax']/100)  ,2)   ;
				}
				
				// 排放测试费 26019
				if(in_array($FRepKey, [ '26019'  ])  ){
					$param['fallamount'] =  ($param['fpfcsfeiyong']??0)   ;
					//排放测试费合计 含税
					$param['ffaxallamount']  = (floatval($param['fpfcsfeiyong'])  )*(1+$param['ffax']/100)   ;
				}
				// 图纸送审费 26020 --不用合计
				if(in_array($FRepKey, [ '26020'  ])  ){
					//$param['fallamount'] =  ($param['ftzssfeiyong']??0)   ;
					//图纸送审费合计 含税
					//$param['ffaxallamount']  = (floatval($param['ftzssfeiyong'])  )*(1+$param['ffax']/100)   ;
				}
				
				// 已录入机型  14008
				if(in_array($FRepKey, [ '14008'  ])  ){
					//本身是否存在该机型
					$ben =  SqlServerUtil::execToSql($this->SqlServer, " select  fmodel from {$db} where fmodel = '{$param['fmodel']}' ",2);
					if(!empty($ben)){
						showMsg(400,'该机型已存在无法新增，请查看');
					}
				}
				
			}
			
			if(in_array($FRepKey, ['30001','40001' ])){
				$param['Fbillno'] = $this->getNumberNO($FRepKey);
			}
			
			$param = array_filter(_unsetNull($param));
 			
			
			$qkid= SqlServerUtil::sqlsrvCreateTosql($this->SqlServer,$db,$param  );
			$this->writeLog(getMkName($FRepKey),'新增' , $FRepKey , $param ,$opername );
			if( in_array($FRepKey, ['26002','25002','25003','25004','25005' ]) ){
				//resMX 
				$resMX = array_filter(_unsetNull($resMX));
				SqlServerUtil::sqlsrvCreateTosql($this->SqlServer,$db.'MX',$resMX  );
				$cs = $this->getSystemProfile(['FSetSendSMS'   ]);
				$this->genSendSms($cs['fsetsendsms'],getMkName($FRepKey).' ，机型为 ' .$param['fmodel'].'已做新增');
			}
			if(in_array($FRepKey, ['14008' ,'26016' ,'26013','26012','26011','26006','26007','26008' ,'28006','28007'   ,'26010','26004','26019','26015'  ]) ){
				$resMX = array_filter(_unsetNull($resMX));
				SqlServerUtil::sqlsrvCreateTosql($this->SqlServer,$db.'MX',$resMX  );
			}
			if($qkid){
				showMsg(200,'保存成功');
			}else{
				showMsg(400,'保存失败');
			}
			
		}else{
			//修改  修改   修改 
			$FItemID = $request->input('fid');
			$where = ['fid'=>$FItemID];
			
			if($FRepKey =='13002' || $FRepKey =='12020' ){
				unset($param['db']);
				unset($param['opername']);
				unset($param['fid']);
				unset($param['FRepKey']);
 				unset($param['fyear']);
 				unset($param['fperiod']);
			
			}else{
				if(in_array($FRepKey, ['12002','12005', '12225'  ])){
					unset($param['fname']);
				}
				unset($param['FRepKey']);
				unset($param['fid']);
				unset($param['db']);
				unset($param['opername']);
				
			}
		
			if($FRepKey =='12013'){
				if(!empty($param['ftsgz']) && $param['ftsgz']>0){
					$param['fjsamount']=$param['ftsgz'];
					$param['fgongshi'] = 0;
					$param['fjsgz'] = 0;
				}else{
					if(empty($param['fgongshi'])){
						$param['fgongshi'] = 1;
					}
					$param['fjsamount']= $param['fgongshi'] * $param['fjsgz'] ;
				}
				
			}
			
			if(in_array($FRepKey, ['30002','40002' ])){
				//这里 成本 
				$where =[];
				 
				$where = ['fitemid'=>$FItemID];
				//没有新增
				 unset($param['fname'])  ;
				 $param['fitemid'] = $FItemID;
				 $sqlStr = "select fbillno from {$db} where fitemid ='{$FItemID}' ";
				$tt =  SqlServerUtil::execToSql($this->SqlServer, $sqlStr,2);
				if(empty($tt)){
					$qkid= SqlServerUtil::sqlsrvCreateTosql($this->SqlServer,$db,$param  );
					$this->writeLog(getMkName($FRepKey),'修改' , $FRepKey , $request->all()  ,$opername);
					if($qkid){
						showMsg(200,'成功');
					}else{
						showMsg(400,'失败');
					}
				}
				 
			}
			
			//26001-- 直接人工费 -- 修改
			if($FRepKey == 26001 ){
				//人工费合计 含税
				$param['ffaxAllAmount']  = (floatval($param['fhanjiecj']) * $param['fhanjieprice'] + floatval($param['fjijiacj']) * $param['fjijiaprice'] + floatval($param['fzhuangshicj']) * $param['fzhuangshiprice'] ) *(1+$param['ffax']/100)   ;
				//人工费合计 
				$param['fallAmount']  = floatval($param['fhanjiecj']) * $param['fhanjieprice'] + floatval($param['fjijiacj']) * $param['fjijiaprice'] + floatval($param['fzhuangshicj']) * $param['fzhuangshiprice'] ;
				//总工时
				$param['fgongshi']  = floatval($param['fhanjiecj']) + floatval($param['fjijiacj']) + floatval($param['fzhuangshicj'])  ;
				 
			}
			
			//26002 -- 船检费CCS  /1.06
			if($FRepKey == 26002 ){
				$tt =  SqlServerUtil::execToSql($this->SqlServer, " select fbrand,fpower from gz_YBaseJS where fmodel = '{$param['fmodel']}' ",2);
				if(empty($tt)){
					showMsg(400,'技术中心没有这个机型，请查看');
				}
				// fzztax 增值税   
				$param['fzztaxamount'] = round(($param['fzjjianyanf'] + $param['fnoxpaifangf'] + $param['flvtuf'] + $param['fjizuojijiaf'] + $param['fzhusuf'] + $param['fjiaotongf'] +  $param['ftongxunf']  +  $param['fzhengshuf'] ) * ($param['fzzfax']/100) ,2) ;
				$CS =  $this->getSystemProfile(['FSetChuanjianCCS']);
				// fallamount 金额
				$param['fallamount']  = $param['fzztaxamount']+ $param['fzjjianyanf'] + $param['fnoxpaifangf'] + $param['flvtuf'] + $param['fjizuojijiaf']	+ $param['fzhusuf'] + $param['fjiaotongf'] +  $param['ftongxunf'] +  $param['fzhengshuf']  + $param['fpaifangtestf']  ;
				$param['fchanjianfeiccs']  = round(($param['fzjjianyanf'] + $param['fnoxpaifangf'] + $param['flvtuf'] + $param['fjizuojijiaf']	+ $param['fzhusuf'] +   $param['fjiaotongf'] 
						+  $param['ftongxunf']  +  $param['fzhengshuf'])/$CS['fsetchuanjianccs'],2)   ;
				
			}
			//25002 -- 船检费ABS
			if($FRepKey == 25002 ){
				$tt =  SqlServerUtil::execToSql($this->SqlServer, " select fbrand,fpower from gz_YBaseJS where fmodel = '{$param['fmodel']}' ",2);
				if(empty($tt)){
					showMsg(400,'技术中心没有这个机型，请查看');
				}
				$huilv = $this->getSystemProfile(['FSetHuiLv'   ]);
				$param['fexchangerate'] = 1;
				if($huilv){
					$param['fexchangerate'] = $huilv['fsethuilv'];
				}
				//整机检验费人民币
				$param['fzjjianyanfrmb'] =  round( $param['fzjjianyanf']*$param['fexchangerate'] ,2);
				//NOX排放费人民币
				$param['fnoxpaifangfrmb'] = round($param['fnoxpaifangf'] *$param['fexchangerate'] ,2) ;
				//证书费人民币
				$param['fzhengshufrmb'] =  round($param['fzhengshuf'] *$param['fexchangerate'] ,2);
				//旅途时间费用人民币
				$param['flvtufrmb'] =  round( $param['flvtuf'] *$param['fexchangerate']*30 ,2) ;
				// fzztax 增值税
				$param['fzztaxamount'] = ($param['fzjjianyanfrmb'] + $param['fnoxpaifangfrmb'] + $param['fzhengshufrmb'] + $param['flvtufrmb'] + $param['fzhusufrmb'] + $param['franyoufrmb'] + $param['fguolufrmb']+  $param['fhuosibutiermb']   ) * ($param['fzzfax']/100)  ;
				
				// fallamount 金额
				$param['fallamount']  = $param['fzztaxamount'] + $param['fzjjianyanfrmb'] + $param['fnoxpaifangfrmb'] + $param['fzhengshufrmb'] + $param['flvtufrmb'] + $param['fzhusufrmb']  +  $param['franyoufrmb'] + $param['fguolufrmb']+  $param['fhuosibutiermb']+  $param['fpaifangtestfrmb']   ;
				//  船检费ABS
				$param['fchanjianfeiabs']  =  $param['fzjjianyanfrmb'] + $param['fnoxpaifangfrmb'] + $param['fzhengshufrmb'] + $param['flvtufrmb'] + $param['fzhusufrmb'] + $param['franyoufrmb'] + $param['fguolufrmb']+  $param['fhuosibutiermb']   ;
				
			}
			//船检费LR
			if($FRepKey == 25003 ){
				$tt =  SqlServerUtil::execToSql($this->SqlServer, " select fbrand,fpower from gz_YBaseJS where fmodel = '{$param['fmodel']}' ",2);
				if(empty($tt)){
					showMsg(400,'技术中心没有这个机型，请查看');
				}
				// fzztax 增值税
				$param['fzztaxamount'] = ($param['fzjjianyanf'] + $param['fnoxpaifangf'] + $param['flvtuf'] + $param['fjizuojijiaf'] + $param['fzhusuf'] + $param['fguoyejintie'] +  $param['franyouf'] + $param['fguoluf']+  $param['fzhengshuf']  ) * ($param['fzzfax']/100)  ;
				
				// fallamount 金额
				$param['fallamount']  = $param['fzztaxamount'] +$param['fzjjianyanf'] + $param['fnoxpaifangf'] + $param['flvtuf'] + $param['fjizuojijiaf']	+ $param['fzhusuf'] + $param['fguoyejintie'] +  $param['franyouf'] + $param['fguoluf']+  $param['fzhengshuf']+  $param['fpaifangtestf']   ;
				$param['fchanjianfeilr']  = $param['fzjjianyanf'] + $param['fnoxpaifangf'] + $param['flvtuf'] + $param['fjizuojijiaf'] + $param['fzhusuf'] + $param['fguoyejintie'] +  $param['franyouf'] + $param['fguoluf']+  $param['fzhengshuf']    ;
				
			}
			//船检费BV
			if($FRepKey == 25004 ){
				$tt =  SqlServerUtil::execToSql($this->SqlServer, " select fbrand,fpower from gz_YBaseJS where fmodel = '{$param['fmodel']}' ",2);
				if(empty($tt)){
					showMsg(400,'技术中心没有这个机型，请查看');
				}
				// fzztax 增值税
				$param['fzztaxamount'] = ($param['fzjjianyanf'] + $param['fnoxpaifangf'] + $param['flvtuf'] + $param['fjizuojijiaf'] + $param['fzhusuf']  +  $param['franyouf'] + $param['fguoluf']+  $param['fzhengshuf']   ) * ($param['fzzfax']/100)  ;
				
				// fallamount 金额
				$param['fallamount']  = $param['fzztaxamount'] +$param['fzjjianyanf'] + $param['fnoxpaifangf'] + $param['flvtuf'] + $param['fjizuojijiaf']	+ $param['fzhusuf'] +  $param['franyouf'] + $param['fguoluf']+  $param['fzhengshuf']+  $param['fpaifangtestf']   ;
				$param['fchanjianfeibv']  = $param['fzjjianyanf'] + $param['fnoxpaifangf'] + $param['flvtuf'] + $param['fjizuojijiaf'] + $param['fzhusuf']  +  $param['franyouf'] + $param['fguoluf']+  $param['fzhengshuf']    ;
				
			}
			//船检费DNV
			if($FRepKey == 25005 ){
				$tt =  SqlServerUtil::execToSql($this->SqlServer, " select fbrand,fpower from gz_YBaseJS where fmodel = '{$param['fmodel']}' ",2);
				if(empty($tt)){
					showMsg(400,'技术中心没有这个机型，请查看');
				}
				// fzztax 增值税
				$param['fzztaxamount'] = ($param['fzjjianyanf'] + $param['fnoxpaifangf'] + $param['flvtuf'] + $param['fjizuojijiaf'] + $param['fzhusuf']  +  $param['franyouf'] + $param['fguoluf']+$param['fchuchaibutie']+  $param['fzhengshuf']   ) * ($param['fzzfax']/100)  ;
				
				// fallamount 金额
				$param['fallamount']  = $param['fzztaxamount'] +$param['fzjjianyanf'] + $param['fnoxpaifangf'] + $param['flvtuf'] + $param['fjizuojijiaf']	+ $param['fzhusuf']  +  $param['franyouf']+ $param['fguoluf'] + $param['fchuchaibutie']+  $param['fzhengshuf']+  $param['fpaifangtestf']   ;
				$param['fchanjianfeidnv']  = $param['fzjjianyanf'] + $param['fnoxpaifangf'] + $param['flvtuf'] + $param['fjizuojijiaf'] + $param['fzhusuf']  +  $param['franyouf']+ $param['fguoluf'] + $param['fchuchaibutie']+  $param['fzhengshuf']    ;
				
			}
			
			//船检费 固定 
			if($FRepKey == 26024 ){
				if($param['ftype'] != 'ABS'){
					//有汇率
					$param['fexchangerate'] = 1 ;
				}
				$param['fzjjianyanf'] = $param['fzjjianyanf'] ;
				$param['fzhengshuf']  = $param['fzhengshuf'] ; 
				$param['flutuf'] = $param['flutuf'] ;
				$param['fpaifangmuxing'] = $param['fpaifangmuxing'] ;
				$param['fpaifangzixing'] = $param['fpaifangzixing'] ;
				// 证书费 + 路途费用  =  确定部分
				$param['fquedingbf'] = ($param['fzhengshuf'] + $param['flutuf']) * $param['fexchangerate'] ; 
				// fallamount 金额
				$param['fallamount'] = ($param['fzjjianyanf'] + $param['fzhengshuf'] + $param['flutuf'] + $param['fpaifangmuxing'] + $param['fpaifangzixing']) * $param['fexchangerate'];
			}
			
			//气油费
			if($FRepKey == 26003 || $FRepKey == 26007  || $FRepKey == 26021){
				//气缸油单价*1.058
				$param['fcylinderoilprice'] =  ($param['fcylinderoilprice']??0)   ;
				
				//油 气  合计
				$param['fAllamount'] = (($param['fdieseloilqty']??0) * ($param['fprice']??0)) + (($param['fcylinderoil']??0) * $param['fcylinderoilprice']) + (($param['fmainoil']??0) * $param['fmainoilprice']) + (($param['fgasqty']??0) * ($param['fgasprice']??0 ) );
			}
			
			//专利
			if($FRepKey == 26004){
				//专利合计
				$param['fPatentfeeAmount'] =  ($param['fexchangerate']??1) * ($param['fpatentfee']??0 ) ;
			}
			//清单费
			if($FRepKey == 26005){
				$param['famount'] =  ($param['fprice']??0) * ($param['fqty']??0 ) ;
			}
			//辅材成本 26008 结构
			if($FRepKey == 26008){  // 暂时
				// 结构车间-制造费用表  用技术中心的自制件重量引过来
				// 按吨位计算的成本 fdunweicb  = 根据单价 乘以 吨位    这里 还差一个 吨位计算成本
				$tt =  SqlServerUtil::execToSql($this->SqlServer, " select fbrand,fpower,fzzjweight  from gz_YBaseJS where fmodel = '{$param['fmodel']}' ",2);
				$param['fzzjweight'] = 0;
				if(!empty($tt)){
					$param['fzzjweight'] = $tt['fzzjweight'];
				}
				
				$param['fdunweicb']  =  ($param['fzzjweight']??0) *  $param['fdunweiprice'] ;
				$param['fallamount'] =  ($param['fzjyouqi']??0) + ($param['ftuihuocb']??0 ) + ($param['fqitaftcb']??0 ) + $param['fdunweicb']??0  ;
			}
			
			//辅材成本 28006  -- 机加工
			if($FRepKey == 28006){ 
				$CS = $this->getSystemProfile(['FSetProdFY'   ]);
				$tt =  SqlServerUtil::execToSql($this->SqlServer, " select  fdaojuxiaohao as fdaojufy from gz_YBaseProduce  where fmodel = '{$param['fmodel']}' ",2);
				$param['fdaojufy'] = 0;
				if(!empty($tt)){
					$param['fdaojufy'] = $tt['fdaojufy'];
				}
				//合计    不需要分摊
				$param['fallamount']  =  ($param['fdaojufy']*$CS['fsetprodfy']??0) + ($param['ffentanfy']??0)  ;
			}
			
			//辅材成本 28007 -- 装试
			if($FRepKey == 28007){    
				// 低耗	包装物   技术中心 引过来
				$tt =  SqlServerUtil::execToSql($this->SqlServer, " select  ffuliao as fdihao , fpackage as fbaozhuangwu,ffuliaopakeage  from gz_YBaseJS  where fmodel = '{$param['fmodel']}' ",2);
				
				$param['fdihao'] = 0;
				$param['fbaozhuangwu'] = 0;
				$yy = $this->getSystemProfile(['fsetfucai535value','fsetfucai550value','fsetfucaibzw535value','fsetfucaibzw550value']);
				$fsetfucaibzw550value = 0 ;
				$fsetfucai550value =0 ;
				$fsetfucaibzw535value = 0 ;
				$fsetfucai535value = 0 ;
				if(!empty($yy)){
					$fsetfucaibzw550value = $yy['fsetfucaibzw550value'] ;
					$fsetfucai550value = $yy['fsetfucai550value'] ;
					
					$fsetfucaibzw535value = $yy['fsetfucaibzw535value'] ;
					$fsetfucai535value = $yy['fsetfucai535value'] ;
				}
				if(!empty($tt)){
					if($tt['ffuliaopakeage'] == '535'){
						$param['fdihao'] = $tt['fdihao']* $fsetfucai535value ;
						$param['fbaozhuangwu'] = $tt['fbaozhuangwu']* $fsetfucaibzw535value ;
					}
					if($tt['ffuliaopakeage'] == '550'){
						$param['fdihao'] = $tt['fdihao']* $fsetfucai550value ;
						$param['fbaozhuangwu'] = $tt['fbaozhuangwu']* $fsetfucaibzw550value ;
					}
				}
// 				dd( $param );
				// 装试车间低耗和包装物系数是根据550或者535计算的
				$param['fallamount'] =  ($param['fdihao']??0) + ($param['fbaozhuangwu']??0 ) + ($param['fyoulvqi']??0 ) + ($param['fqitayoupin']??0)  + ($param['ffentanfycj']??0 ) + ($param['ffentanfysczl']??0)  ;
			}
			//采购成本 26009 
			if($FRepKey == 26009 || $FRepKey == 26022 ){
				$param['fnotfaxamount'] =  ($param['fnotfaxamount']??0)  ;
				$param['ffaxamount'] =  ($param['fnotfaxamount']??0) *(1+$param['ffax']/100) ;
			}
			
			// 折旧费  26010  折旧用各车间折旧总金额/台数
			if($FRepKey == 26010){
				$param['fhanjiecjzj'] = round( ($param['fhanjiecj']??0) /($param['fhanjieqty']==0? 1:$param['fhanjieqty']),2)  ;
				$param['fjijiacjzj'] =   round( ($param['fjijiacj']??0 ) /($param['fjijiaqty']==0? 1:$param['fjijiaqty']),2)  ;
				$param['fzhuangshicjzj'] =  round( ($param['fzhuangshicj']??0 )/($param['fzhuangshiqty']==0? 1:$param['fzhuangshiqty']),2)   ;
				
				$param['fcjzjamount'] =  ($param['fhanjiecjzj']??0) + ($param['fjijiacjzj']??0 ) + ($param['fzhuangshicjzj']??0 ) ;
			}
		 
			//水电合计 26011
			if($FRepKey == 26011){
				// 结构车间水电费  : 一种是按照吨位计算，即吨位单价乘以吨位；  一种是固定金额 fhanjiecj
				// 结构车间水电费  : 一种是按照吨位计算，即吨位单价乘以吨位；  一种是固定金额 fhanjiecj
				// 结构车间吨位	fjgcjdw  -- 技术中心  ，，  自制件重量
				// 结构车间吨位单价	fjgcjdwprice   -- 参数获取
				$param['fjgcjdw'] = 0 ;
				$param['fjgcjdwprice'] = 0;
				$sd = $this->getSystemProfile(['FSetShuiDianjgcjPrice'   ]);
				if($sd){
					$param['fjgcjdwprice'] = empty($sd['fsetshuidianjgcjprice'])?0:$sd['fsetshuidianjgcjprice'];
				}
				$tt =  SqlServerUtil::execToSql($this->SqlServer, " select   fzzjweight    from gz_YBaseJS  where fmodel = '{$param['fmodel']}' ",2);
				if($tt){
					$param['fjgcjdw'] = $tt['fzzjweight'];
				}
				
				$param['fjgcjdwamount'] =  ($param['fjgcjdw']??0) * ($param['fjgcjdwprice']??0)  ;
				//水电费合计
				$param['fallamount'] =  ($param['fjgcjdwamount']??0) + ($param['fjijiacj']??0 ) + ($param['fzhuangshicj']??0 )  + ($param['fhanjiecj']??0 ) ;
				//水电费合计 含税
				$param['ffaxallamount']  = (floatval($param['fjgcjdwamount'])  + floatval($param['fjijiacj'])  + floatval($param['fzhuangshicj']) + ($param['fhanjiecj']??0 ))*(1+$param['ffax']/100)   ;
			}
			
			//售后调试成本  26012
			if($FRepKey == 26012){
				// 1.按照售后差旅+人工+材料；   ，，	一种是固定金额 fshguding
				//售后调试成本
				$param['fallamount'] =  ($param['fshcailiao']??0) + ($param['fshrengong']??0 ) + ($param['fshchailv']??0 )+($param['fshguding']??0) ;
				//售后调试成本
				$param['ffaxallamount']  = (($param['fshcailiao']??0) + ($param['fshrengong']??0 ) + ($param['fshchailv']??0 )+($param['fshguding']??0) )*(1+$param['ffax']/100)   ;
			}
			
			// 质量成本  26013
			if($FRepKey == 26013){
				// 1.按照售后差旅+人工+材料；   ，，	一种是固定金额 fzlguDing
// 				$param['fallamount'] =  ($param['fzlguding']??0)  ;
				//售后调试成本
				$param['fallamount'] =  ($param['fcaigouamount']??0) + ($param['fjishuamount']??0 )  +($param['fzlguding']??0) ;
				//售后调试成本  含税
				$param['ffaxallamount']  = ( ($param['fcaigouamount']??0) + ($param['fjishuamount']??0 ) +($param['fzlguding']??0)  )*(1+$param['ffax']/100)   ;
			}
			
			//委外费用 26014
			if($FRepKey == 26014){
				//委外费用合计
				$param['fallamount']= $param['fjuanyuan'] + $param['flingxingjg']+ $param['fsuanxi']+ $param['fjizuo']+ $param['fjijia'] 
				+ $param['fqita']+ $param['fpaiyanguan']+ $param['fzoutai']+ $param['fgzfentan']+ $param['fpaiyanguanbgr']+ $param['fjinqixiang']+ $param['fzjguan']   ;
				//图纸费合计 含税
				$param['ffaxallamount']  = ($param['fjuanyuan'] + $param['flingxingjg']+ $param['fsuanxi']+ $param['fjizuo']+ $param['fjijia']
						+ $param['fqita']+ $param['fpaiyanguan']+ $param['fzoutai']+ $param['fgzfentan']+ $param['fpaiyanguanbgr']+ $param['fjinqixiang']+ $param['fzjguan'] )*(1+$param['ffax']/100)   ;
			}
			
			//图纸费 26015
			if(in_array($FRepKey, [ '26015'  ])  ){
				//WINGD:第一次判断是否同样的机，有，为0;
				//没有，进行二次判断，判断是不是同样的机型不同的缸数， 有，则按照不同缸数收费，  无，就按照首台
				//MAN:第一次判断是否同样的机，有，按照不同应用型式；
				//没有，进行二次判断，判断是不是同样的机型不同的缸数， 有，则按照不同缸数收费；无，就按照首台。
				$tz = $this->getSystemProfile(['FSetHuiLv','FSetHuiLvFaLang','FSetHuiLvOyuan'   ]);
				$param['fexchangerate'] = strtoupper($param['fbrand']) == 'WINGD'?$tz['fsethuilvfalang']:$tz['fsethuilvoyuan'] ;
				$param['fallamount'] =  round($param['ftzfeiyong']* $param['fexchangerate'] ,2)   ;
				//图纸合计 含税
				$param['ffaxallamount']  = round((floatval($param['ftzfeiyong']*$param['fexchangerate'])  )*(1+$param['ffax']/100) ,2)  ;
			}
			
			//运保费 26016 -- 修改 
			if(in_array($FRepKey, [ '26016'  ])  ){
				//1.保险费： 用销售金额乘以费率 *（1+增值税率） / 1.06
				//2.运输费。运输地点，海里数，单位海里价格  * 1.13 /1.09
				$param['fbaoxianfei'] = $param['fsaleamount'] * ($param['ffeilv']??0)  ;
				
				$param['fyunshufei'] =  $param['fhailishu'] *  $param['fhailiprice']  ;
				$CS =  $this->getSystemProfile(['FSetTuZhiSS' , 'FSetYunBaoF']);
				//$param['fallamount'] =  ($param['fysguding']??0)  ;
				//运保费合计
				$param['fallamount'] =  round($param['fbaoxianfei'] *(1+$param['ffax']/100) / $CS['fsettuzhiss'] ,2) 
				+  round(($param['fyunshufei']+  $param['fysguding'])*(1+$param['ffax']/100) /  $CS['fsetyunbaof'],2)    ;
				//运保费合计 含税
				//$param['ffaxallamount']  =  round($param['fbaoxianfei'] *(1+$param['ffax']/100) / 1.06 ,2) +  round($param['fyunshufei']*(1+$param['ffax']/100) / 1.09,2)    ;
				
			}
			
			//特定工装 26017 --xiugai
			if(in_array($FRepKey, [ '26017'  ])  ){
				// 特定工装  整体发运 合计
				// 整体发运  前面五项/分摊的台数+第六项
				$param['fztfyAmount'] = round( ($param['fzjguan']+$param['fhanjiegz']+$param['fjijiagz'] + $param['fzhuangshigz']+$param['fshichegz'])/(empty($param['ffentantaishu'])?1:$param['ffentantaishu'] )  ,2)+$param['ffayungzzj']    ;
				// 分体发运 合计   2.前面五项/分摊的台数+第七项
				$param['fftfyAmount'] = round( ($param['fzjguan']+$param['fhanjiegz']+$param['fjijiagz'] + $param['fzhuangshigz']+$param['fshichegz']) /(empty($param['ffentantaishu'])?1:$param['ffentantaishu'] )  ,2) +$param['ffayungzfd']    ;
				
			}
			
			//特定刀具 26018
			if(in_array($FRepKey, [ '26018'  ])  ){
				// +($param['fdjuxiaohao']??0)
				// 用特殊刀具/分摊的台数
				$param['fallamount'] = round( (($param['fxjxtsdaoju']??0)  ) /( empty($param['ffentantaishu'])?1:$param['ffentantaishu'] )  ,2) ;
				//特殊刀具合计 含税
				$param['ffaxallamount']  = round( (($param['fxjxtsdaoju']??0)  ) /( empty($param['ffentantaishu'])?1:$param['ffentantaishu'] ) *(1+$param['ffax']/100)  ,2)   ;
			}
			 
			
			// 排放测试费 26019
			if(in_array($FRepKey, [ '26019'  ])  ){
				// 不带DF\SCR\EGR\LGIM就按照普通机型
				
				$param['fallamount'] =  ($param['fpfcsfeiyong']??0)   ;
				//排放测试费合计 含税
				$param['ffaxallamount']  = (floatval($param['fpfcsfeiyong'])  )*(1+$param['ffax']/100)   ;
			}
			// 图纸送审费 26020
			if(in_array($FRepKey, [ '26020'  ])  ){
				 
				//$param['fallamount'] =  ($param['ftzssfeiyong']??0)   ;
				//图纸送审费合计 含税
				//$param['ffaxallamount']  = (floatval($param['ftzssfeiyong'])  )*(1+$param['ffax']/100)   ;
			}
			
			if(in_array($FRepKey, [ '14020'  ])  ){
// 				dd($param);
				//$param['fallamount'] =  ($param['ftzssfeiyong']??0)   ;
				//图纸送审费合计 含税
				//$param['ffaxallamount']  = (floatval($param['ftzssfeiyong'])  )*(1+$param['ffax']/100)   ;
			}
			
// 			$param = array_filter(_unsetNull($param));
// 			dd($param);
			$param['fcreatetime'] = getCurrentTime();
			
			$qkidupdate= SqlServerUtil::exeupdateTosql($this->SqlServer,$db,$param,$where);
			//这里针对 船检费 发送給 指定人 
			if( in_array($FRepKey, ['26002','25002','25003','25004','25005' ]) ){
				$cs = $this->getSystemProfile(['FSetSendSMS'   ]);
				$this->genSendSms($cs['fsetsendsms'],getMkName($FRepKey).' ，机型为' .$param['fmodel'].'已做修改');
				SqlServerUtil::sqlsrvCreateTosql($this->SqlServer,$db.'MX',$resMX  );
			}
			
			if(in_array($FRepKey, ['14008' ,'26016' ,'26013','26012','26011','28006','28007','26008'    ,'26010','26004','26019','26015' ]) ){
// 				dd( $db.'MX', $resMX );
				SqlServerUtil::sqlsrvCreateTosql($this->SqlServer,$db.'MX',$resMX  );
			}
			
			$this->writeLog(getMkName($FRepKey),'修改' , $FRepKey , $request->all()  ,$opername);
			if($qkidupdate){
				showMsg(200,'修改成功');
			}else{
				showMsg(400,'修改失败');
			}
		}
	}
	/**
	* 聚一科技 ^_^
	* 删除
	* @date: 2020年9月7日
	* @author: lq
	* @version:App V2.0
	*/
	public function genDel(Request $request)
	{
		$FRepKey= $request->get('FRepKey');
		$db = columnBiao($FRepKey);//表名
		$FItemID = $request ->get('fid');
		$opername  = $request ->get('opername')?$request ->get('opername') :'';
		$data  = $request ->get('data');
		//判断
		if($data){
			//船级社其他 
			if(in_array($FRepKey, ['25007'  ])){
				foreach ($data as $k =>$v)
				{
					$selectData = SqlServerUtil::execTosql($this->SqlServer, "select fqrCW,opernameCW,fisqr  from gz_YBaseSC where fbillno ='{$v['fjybjbillno']}'",2 );
					if(!empty($selectData['fqrCW'] )  ){
						showMsg(400,'流水号：'.$v['fjybjbillno'].' , 业务需求（财务）已做确认操作，无法删除，请检查') ;
					}
				}
			}
			
			if(in_array($FRepKey, ['30004'  ])){
				foreach ($data as $k =>$v)
				{
					if($v['fstatus'] == 1){
						showMsg(400,'已经审核不能删除'.$v['fbillno']);
					}
				}
			}
			//数据库信息技术 
			if(in_array($FRepKey, ['27010'  ])){
				if($data){
					foreach ($data as $k =>$v)
					{
						if($v['fstatus'] == 1){
							showMsg(400, '型 号：'. $v['fegcmodel'].' 无法删除  ，采购部已经审核，请知会。' );
						}
					}
				}
			}
			//数据库信息采购  cg
			if(in_array($FRepKey, ['27011'  ])){
				if($data){
					foreach ($data as $k =>$v)
					{
						if($v['fstatuscg'] == 1){
							showMsg(400, '型号 ：'. $v['fegcmodel'].' 无法删除  ,技术部已经审核，请知会。' );
						}
					}
				}
			}
			//ICER燃气版其他成本
			if(in_array($FRepKey, ['27006' ,'27007','27015' ,'27001' ,'27012'])){
				if($data){
					foreach ($data as $k =>$v)
					{
						//判断是否已生成加载信息
						$resJZ = SqlServerUtil::execToSql($this->SqlServer, "select FStatus ,fbillno,fisqr from  gz_YbaojiadanCB where fbillno ='{$v['fbillno']}'" ,2 );
						if($resJZ){
							showMsg(400, '流水号 ：'. $v['fbillno'].' 已生成正式报价，无法删除  ' );
						}
						
						if(in_array($FRepKey, ['27007' ])){
							SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_YjzJiaChunQTYouHao' , ['fbillno'=> $v['fbillno'] ] );
							
							SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_YjzSCREGRHZ' , ['fbillno'=> $v['fbillno'] ] );
						}elseif(in_array($FRepKey, ['27006' ])){
							SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_YjzICERrqbyouqiNOst' , ['fbillno'=> $v['fbillno'] ] );
							SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_YjzICERrqbyouqist' , ['fbillno'=> $v['fbillno'] ] );
							
							SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_YjzSCREGRHZ' , ['fbillno'=> $v['fbillno'] ] );
						}elseif(in_array($FRepKey, ['27015' ])){
							SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_YjzICERrybyouqist' , ['fbillno'=> $v['fbillno'] ] );
							SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_YjzICERrybyouqiNOst' , ['fbillno'=> $v['fbillno'] ] );
							
							SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_YjzSCREGRHZ' , ['fbillno'=> $v['fbillno'] ] );
						}elseif(in_array($FRepKey, ['27001' ])){
							SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_YjzSCREGRNost' , ['fbillno'=> $v['fbillno'] ] );
							SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_YjzSCREGRst' , ['fbillno'=> $v['fbillno'] ] );
							
							SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_YjzSCREGRHZ' , ['fbillno'=> $v['fbillno'] ] );
						}elseif(in_array($FRepKey, ['27012' ])){
							SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_YjzECOEGRst' , ['fbillno'=> $v['fbillno'] ] );
							SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_YjzECOEGRNost' , ['fbillno'=> $v['fbillno'] ] );
							
							SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_YjzSCREGRHZ' , ['fbillno'=> $v['fbillno'] ] );
						}
						 
					}
				}
			}
			
			
			
		}
		
		if( in_array($FRepKey, ['12001','14001','14002' ]) ){
			$qkid = sqlsrv_query($this->SqlServer,"DELETE {$db} WHERE FItemID in ({$FItemID}) ");
		}elseif(in_array($FRepKey, ['30001','40001'])){
			if($FRepKey =='30001' ){
				$db1 = columnBiao(30002);
			}elseif ($FRepKey =='40001'){
				$db1 = columnBiao(40002);
			}
			$qkid = sqlsrv_query($this->SqlServer,"DELETE {$db1} WHERE FItemID in ({$FItemID}) ");
		}else{
			$qkid = sqlsrv_query($this->SqlServer,"DELETE {$db} WHERE fid in ({$FItemID}) ");
		}
		if($qkid){
			$this->writeLog(getMkName($FRepKey),'删除' , $FRepKey , $data ,$opername);
			showMsg(200,'删除成功');
		}else{
			showMsg(400,'删除失败');
		}
		
	}
	
	/**
	* 聚一科技 ^_^
	* 批量删除
	* @date: 2020年11月9日
	* @author: lq
	* @version:App V2.0
	*/
	public function genPlDel(Request $request)
	{
		$FRepKey= $request->get('FRepKey');
		if(empty($FRepKey)){
			showMsg(1,'参数传参错误');
		}
		$db = columnBiao($FRepKey);//表名
		$qkid = sqlsrv_query($this->SqlServer,"DELETE {$db} ");
		if($qkid){
			showMsg( 0,'删除成功');
		}else{
			showMsg(1,'删除失败');
		}
		
	}
	
	
	
	/**
	* 聚一科技 ^_^
	* @date: 2020年9月7日
	* @author: lq
	* @version:App V2.0
	*/
	public function genList(Request $request)
	{
		$FRepKey  = $request->get('FRepKey');//对象代号
		if(empty($FRepKey)){
			showMsg(1,'对象代号不存在');
		}
		$page= $request ->get('page');
		if(!isset($page)) $page =1;
		$limit= $request ->get('limit');
		if(!isset($limit)) $limit =10;
		$pages = ($page-1)* $limit;
		$keywordStr='';
		$timeStr='';
		$appStr ='';
		
		//开始时间--结束时间
		$dateStr = '';
		$fcompanyStr ='';
		$fbatchnoStr =  '';
		$fdepStr ='';
		$fcategoryStr ='';
		
		$fdepmentStr ='';
		
		//船级社 
		$fchuanjisheStr ="";
		
		//品牌
		$fbrandStr = "";
		
		//备件报价
		$baojiaStr = '';
		
		//成本部门
		$cbbumenstr ='';
		
		//业务需求
		$fisqrStr ='';
		//年度
		$yearstr = "" ;
		
		// 26001  直接人工成本单价
		$fhanjiePriceStr = 0;
		$fjijiaPriceStr = 0;
		$fzhuangshipriceStr = 0; 
		
		$FSetQiGangPriceStr = 0; 
		$FSetChaiYouPriceStr = 0; //柴油
		$FSetZhuHunYouPriceStr = 0;//主滑油
		$FSetRanqiPriceStr = 0;
		//针对  加账SCR/ICER管理
		$scrEgrStr ="";
		$ranyouHzStr = "";
		$jiachunStr = "";
		$fisjiachunStr ='';
		//分析报表弹框 过滤
		$fenXiStr ="";
		
		//正式 -- 已完成
		$wanchengStr ="";
		//燃油汇总 
		$fisranyouhzStr = "";
		//船级社其他 
		$chuanjisheQTStr = ""; 
		
		//计件
		if($FRepKey == '12225'){
			if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
				$keyword = $request->keyword;
				$keywordStr=" and (charindex('{$keyword}',v1.FItemIDNumber)>0 or charindex('{$keyword}',v1.FItemIDName)>0 or charindex('{$keyword}',v1.FEntryText2)>0 or charindex('{$keyword}',t1.FNumber)>0  or charindex('{$keyword}',t1.FName)>0  or charindex('{$keyword}',t1.Fcompany)>0  or charindex('{$keyword}',sub4.Fname)>0 )";
			}
			
			if ($request->has('fbatchno') and $request->fbatchno != '' and !empty($request->fbatchno)) {
				$fbatchno = $request->fbatchno;
				$fbatchnoStr=" and v1.FBatchNo =  '{$fbatchno}' ";
			}
			
			if ($request->has('appname') and $request->appname != '' and !empty($request->appname)) {
				$appname = $request->appname;
				$appStr=" and v1.FCustItemName ='{$appname}' ";
			}
			
			if ($request->has('fcompany') and $request->fcompany != '' and !empty($request->fcompany)) {
				$fcompanyname = $request->fcompany;
				$fcompanyStr=" and t1.fcompany = '{$fcompanyname}'";
			}
			
			if ($request->has('fdeptname') and $request->fdeptname != '' and !empty($request->fdeptname)) {
				$fdeptname =  $request->fdeptname ;
				$fdepStr=" and (sub4.fname = '{$fdeptname}' )";
			}
			 
			
			$patten = "/^[1-9]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/";
			if ($request->has('start_time') and $request->start_time != '' and $request->start_time != 'null') {
				if($request->has('end_time') and $request->end_time != '' and $request->end_time != 'null'){
					if(preg_match($patten,$request->end_time))
					{
						$etime = $request->end_time;
					}else{
						showMsg(400,'结束时间格式不正确');
					}
				}
				if(preg_match($patten,$request->start_time))
				{
					$stime = $request->start_time;
					$dateStr="and  v1.FDateSC >='{$stime} 00:00:00' and  v1.FDateSC<= '{$etime} 23:59:59' "	;
				}else{
					showMsg(400,'时间格式不正确');
				}
			}
			
		}elseif($FRepKey == '12013'){
			if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
				$keyword =$request->keyword;
				$keywordStr=" and ( charindex('{$keyword}',t1.FNumber)>0 or charindex('{$keyword}',t1.FName)>0 or charindex('{$keyword}',v1.FBatchNo)>0 or charindex('{$keyword}',t1.FNumber)>0 or charindex('{$keyword}',t1.Fcompany)>0  or charindex('{$keyword}',sub4.Fname)>0 )";
			}
			
			if ($request->has('fbatchno') and $request->fbatchno != '' and !empty($request->fbatchno)) {
				$fbatchno = $request->fbatchno;
				$fbatchnoStr=" and v1.FBatchNo ='{$fbatchno}'  ";
			}
			
			//fcompany
			if ($request->has('fcompany') and $request->fcompany != '' and !empty($request->fcompany)) {
				$fcompanyname =  $request->fcompany ;
				$fcompanyStr=" and t1.fcompany = '{$fcompanyname}'";
			}
			
			
			if ($request->has('appname') and $request->appname != '' and !empty($request->appname)) {
				$appname =  $request->appname ;
				$appStr=" and v1.appLogin ='{$appname}' ";
			}
			
			
			if ($request->has('fdeptname') and $request->fdeptname != '' and !empty($request->fdeptname)) {
				$fdeptname =  $request->fdeptname ;
				$fdepStr=" and (sub4.fname = '{$fdeptname}' )";
			}
			
		}elseif($FRepKey == '13002'){
			if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
				$keyword = $request->keyword ;
				$keywordStr=" and ( charindex('{$keyword}',v1.fparentname)>0 or charindex('{$keyword}',t1.FNumber)>0 or charindex('{$keyword}',t1.FName)>0 )";
			}
			
			if ($request->has('fdeptname') and $request->fdeptname != '' and !empty($request->fdeptname)) {
				$fdeptname =  $request->fdeptname ;
				$fdepStr=" and (sub4.fname = '{$fdeptname}' )";
			}
			
		}elseif($FRepKey == '12020'){
			if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
				$keyword = $request->keyword ;
				$keywordStr=" and (charindex('{$keyword}',v1.FName)>0 )";
			}
			
			if ($request->has('fdeptname') and $request->fdeptname != '' and !empty($request->fdeptname)) {
				$fdeptname =  $request->fdeptname ;
				$fdepStr=" and (sub4.fname = '{$fdeptname}' )";
			}
			
		}elseif($FRepKey == '14001'){
			if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
				$keyword = $request->keyword ;
				$keywordStr=" and ( charindex('{$keyword}',v1.FName)>0  or charindex('{$keyword}',v1.Fnumber)>0 or charindex('{$keyword}',v1.fmodel)>0 or charindex('{$keyword}',v1.fhelpcode)>0 or charindex('{$keyword}',v1.FAlias)>0 )";
			}
			
			if ($request->has('fdeptname') and $request->fdeptname != '' and !empty($request->fdeptname)) {
				$fdeptname =  $request->fdeptname ;
				$fdepStr=" and (sub4.fname = '{$fdeptname}' )";
			}
			$patten = "/^[1-9]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/";
			if ($request->has('start_time') and $request->start_time != '' and $request->start_time != 'null') { 
				if($request->has('end_time') and $request->end_time != '' and $request->end_time != 'null'){
					if(preg_match($patten,$request->end_time))
					{
						$etime = $request->end_time;
					}else{
						showMsg(400,'结束时间格式不正确');
					}
				}
				if(preg_match($patten,$request->start_time))
				{
					$stime = $request->start_time;
					$dateStr="and v1.FLastCheckDate >='{$stime}' and v1.FLastCheckDate<= '{$etime} 23:59:59'  "	;
				}else{
					showMsg(400,'时间格式不正确');
				}
			}
			
		}elseif($FRepKey == '14002'){
			if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
				$keyword = $request->keyword ;
				$keywordStr=" and (charindex('{$keyword}',v1.FCategory)>0 or  charindex('{$keyword}',v1.FKey)>0  or charindex('{$keyword}',v1.FValue)>0 or charindex('{$keyword}',v1.FDescription)>0 or charindex('{$keyword}',v1.FExplanation)>0 )";
			}
			if ($request->has('fcategory') and $request->fcategory != '' and !empty($request->fcategory)) {
				$fcategory = $request->fcategory ;
				$fcategoryStr=" and v1.FCategory = '{$fcategory}' ";
			}
			
			
			if ($request->has('fdeptname') and $request->fdeptname != '' and !empty($request->fdeptname)) {
				$fdeptname =  $request->fdeptname ;
				$fdepStr=" and (sub4.fname = '{$fdeptname}' )";
			}
			
			
		}elseif($FRepKey == '14003'){
			if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
				$keyword = $request->keyword ;
				$keywordStr=" and ( charindex('{$keyword}',tp.FName)>0 or charindex('{$keyword}',v1.Fname)>0 or charindex('{$keyword}',v1.FObjectType)>0  or charindex('{$keyword}',v1.FObjectID)>0  )";
			}
			
			if ($request->has('fdeptname') and $request->fdeptname != '' and !empty($request->fdeptname)) {
				$fdeptname =  $request->fdeptname ;
				$fdepStr=" and (sub4.fname = '{$fdeptname}' )";
			}
			
		}elseif($FRepKey == '14004'){
			if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
				$keyword =  $request->keyword ;
				$keywordStr=" and (  charindex('{$keyword}',v1.FName)>0 or charindex('{$keyword}',v1.objectid)>0    )";
			}
			
			if ($request->has('fcompany') and $request->fcompany != '' and !empty($request->fcompany)) {
				$fcompanyname =  $request->fcompany ;
				$fcompanyStr=" and v1.fcompany ='{$fcompanyname}'";
			}
			
			if ($request->has('fdeptname') and $request->fdeptname != '' and !empty($request->fdeptname)) {
				$fdeptname =  $request->fdeptname ;
				$fdepStr=" and (sub4.fname = '{$fdeptname}' )";
			}
			
			$patten = "/^[1-9]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/";
			if ($request->has('start_time') and $request->start_time != '' and $request->start_time != 'null') {
				if($request->has('end_time') and $request->end_time != '' and $request->end_time != 'null'){
					if(preg_match($patten,$request->end_time))
					{
						$etime = $request->end_time;
					}else{
						showMsg(400,'结束时间格式不正确');
					}
				}
				if(preg_match($patten,$request->start_time))
				{
					$stime = $request->start_time;
					$timeStr="and v1.create_at >='{$stime}' and v1.create_at<= '{$etime} 23:59:59'  "	;
				}else{
					showMsg(400,'时间格式不正确');
				}
			}
			 
			
		}elseif($FRepKey == '14005'){
			if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
				$keyword =  $request->keyword ;
				$keywordStr=" and ( charindex('{$keyword}',adm.username)>0 or charindex('{$keyword}',v1.user_agent)>0 or charindex('{$keyword}',v1.ip_address)>0 or charindex('{$keyword}',v1.location)>0)";
			}
			
			$patten = "/^[1-9]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/";
			if ($request->has('start_time') and $request->start_time != '' and $request->start_time != 'null') {
				if($request->has('end_time') and $request->end_time != '' and $request->end_time != 'null'){
					if(preg_match($patten,$request->end_time))
					{
						$etime = $request->end_time;
					}else{
						showMsg(400,'结束时间格式不正确');
					}
				}
				if(preg_match($patten,$request->start_time))
				{
					$stime = $request->start_time;
					$dateStr="and v1.createtime >='{$stime}' and v1.createtime<= '{$etime} 23:59:59' "	;
				}else{
					showMsg(400,'时间格式不正确');
				}
			}
			
			
			if ($request->has('fdeptname') and $request->fdeptname != '' and !empty($request->fdeptname)) {
				$fdeptname =  $request->fdeptname ;
				$fdepStr=" and (sub4.fname = '{$fdeptname}' )";
			}
			
		}elseif(in_array($FRepKey, ['14006'   ]) ){
			if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
				$keyword =  $request->keyword ;
				$keywordStr=" and ( charindex('{$keyword}',v1.FName)>0 ) ";
			}
			 
			
		}elseif(in_array($FRepKey, ['14007'   ]) ){
			if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
				$keyword =  $request->keyword ;
				$keywordStr=" and ( charindex('{$keyword}',v1.fmodel)>0 or charindex('{$keyword}',v1.fbrand)>0      ) ";
			}
			if ($request->has('fbrand') and $request->fbrand != '' and !empty($request->fbrand)) {
				$fbrand =  $request->fbrand ;
				$fbrandStr=" and v1.fbrand = '{$fbrand}'  ";
			}
			
		}elseif(in_array($FRepKey, ['14008'   ]) ){
			if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
				$keyword =  $request->keyword ;
				$keywordStr=" and ( charindex('{$keyword}',v1.fmodel)>0 or charindex('{$keyword}',v1.fbrand)>0      ) ";
			}
			if ($request->has('fbrand') and $request->fbrand != '' and !empty($request->fbrand)) {
				$fbrand =  $request->fbrand ;
				$fbrandStr=" and u1.fbrand = '{$fbrand}'  ";
			}
			
		}elseif(in_array($FRepKey, ['14009'   ]) ){
			//140011 -- 技术	, 14012  -- 采购	,140013 -- 财务, 140011 -- 市场
			if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
				$keyword =  $request->keyword ;
				
				$keywordTmp = explode(',',$keyword);
				if(count($keywordTmp)>1){
					$tmp14009 = '';
					foreach ($keywordTmp as $v)
					{
						$tmp14009 .= " or charindex('{$v}',v1.Fmodel)>0 or charindex('{$keyword}',v1.fcustomer)>0 or charindex('{$keyword}',v1.fcustomerName )>0 or charindex('{$v}',v1.Fbillno)>0 " ;
					}
					$keywordStr=' and ( '.trim($tmp14009,' or') .")";
				}else{
					$keywordStr=" and ( charindex('{$keyword}',v1.fmodel)>0 or charindex('{$keyword}',v1.fcustomer)>0 or charindex('{$keyword}',v1.fcustomerName )>0 or charindex('{$keyword}',v1.fbillno )>0  ) ";
				}
				
			}
			//SCREGR 数据  tkkey   
			if($request->tkkey == '27001' ){
				$scrEgrStr = "  and  not EXISTS ( SELECT fbillno FROM gz_YjzSCREGRNOcbHZ hz where 1 = 1 and v1.fbillno = hz.fbillno )
									 and not EXISTS ( SELECT fbillno FROM gz_YjzECOEGRNOcbHZ hz where 1 = 1 and v1.fbillno = hz.fbillno )
									 and not EXISTS ( SELECT fbillno FROM gz_YjzICERQT hz where 1 = 1 and v1.fbillno = hz.fbillno ) 
									 and not EXISTS ( SELECT fbillno FROM gz_YjzICERRanYouHZ hz where 1 = 1 and v1.fbillno = hz.fbillno ) 

									 and not EXISTS ( SELECT fbillno FROM gz_YjzJiaChunQT hz where 1 = 1 and v1.fbillno = hz.fbillno )
				 and  not EXISTS ( SELECT fbillno FROM gz_YjzSCREGRHZ hz where 1 = 1 and v1.fbillno = hz.fbillno ) "  ;
				
				//是否是甲醇机     1-不是，2-- 是
// 				if($request->fisjiachun == 1){
// 					$jiachunStr  = "  and charindex('LGIM',v1.fmodel) <1  ";
// 				}elseif($request->fisjiachun == 2){
// 					$jiachunStr  = "  and charindex('LGIM',v1.fmodel)>0  and  not EXISTS ( SELECT fbillno FROM gz_YjiachunHZ hz where fstatus = 1 and v1.fbillno = hz.fbillno )   ";
// 				}
			}
			//燃油汇总 
			if($request->tkkey == '29002' ){
				$ranyouHzStr = "  and  not EXISTS ( SELECT fbillno FROM gz_YranyouHZ hz where 1 = 1 and fstatus = 1 and v1.fbillno = hz.fbillno ) 
				 and  charindex('LGIM',v1.fmodel)=0  ";
			}
			//甲醇机 汇总 
			if($request->tkkey == '29011' ){
				$jiachunStr = " and charindex('LGIM',v1.fmodel)>0  and  not EXISTS ( SELECT fbillno FROM gz_YjiachunHZ hz where fstatus = 1 and v1.fbillno = hz.fbillno ) "  ;
			}
			
			// 船级社其他  25007 
			if($request->tkkey == '25007' ){
				$controller = app('App\Http\Controllers\Api\BaseController');
				$request ->fcsjval = 4;
				$request ->fbackval = 1;
				$tempArr = $controller->FcenshuCSJSet($request ) ;
				if(count($tempArr)>=1){
					$tmp25007 = '';
					foreach ($tempArr as $v)
					{
						$tmp25007 .= " or charindex('{$v}',v1.fchuanjishe)>0 " ;
					}
					$chuanjisheQTStr=' and  not EXISTS ( SELECT fjybjbillno FROM gz_YchuanjianfQT qt where   v1.fbillno = qt.fjybjbillno )  and ( '.trim($tmp25007,' or') .")";
				}
			}
			 
			
		}elseif(in_array($FRepKey, ['14010'   ]) ){
			if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
				$keyword =  $request->keyword ;
				$keywordTmp = explode(',',$keyword);
				if(count($keywordTmp)>1){
					$tmp14010 = '';
					foreach ($keywordTmp as $v)
					{
						$tmp14010 .= " or charindex('{$v}',v1.Fmodel)>0  or charindex('{$v}',v1.Fbillno)>0 " ;
					}
					$keywordStr=' and ( '.trim($tmp14010,' or') .")";
				}else{
					$keywordStr=" and ( charindex('{$keyword}',v1.fmodel)>0 or charindex('{$keyword}',v1.fbrand)>0  ) ";
				}
			}
			if ($request->has('fbrand') and $request->fbrand != '' and !empty($request->fbrand)) {
				$fbrand =  $request->fbrand ;
				$fbrandStr=" and v1.fbrand = '{$fbrand}'  ";
			}
			
		}elseif(in_array($FRepKey, [  '14011',  ]) ){
			//140011 -- 技术
			if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
				$keyword =  $request->keyword ;
				$keywordTmp = explode(',',$keyword);
				if(count($keywordTmp)>1){
					$tmp14011 = '';
					foreach ($keywordTmp as $v)
					{
						$tmp14011 .= " or charindex('{$v}',v1.Fmodel)>0 or charindex('{$v}',v1.fcustomer)>0 or charindex('{$v}',v1.fcustomerName )>0 or charindex('{$v}',v1.fmodelNO)>0 or charindex('{$v}',v1.Fbillno)>0 " ;
					}
					$keywordStr=' and ( '.trim($tmp14011,' or') .")";
				}else{
					$keywordStr=" and ( charindex('{$keyword}',v1.fmodel)>0 or charindex('{$keyword}',v1.fcustomer)>0 or charindex('{$keyword}',v1.fcustomerName )>0 or charindex('{$keyword}',v1.fmodelNO)>0 or charindex('{$keyword}',v1.fbillno )>0  ) ";
				}
			}
			
		}elseif(in_array($FRepKey, [ '14012'  ]) ){
			// 14012  -- 采购
			if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
				$keyword =  $request->keyword ;
				$keywordTmp = explode(',',$keyword);
				if(count($keywordTmp)>1){
					$tmp14012 = '';
					foreach ($keywordTmp as $v)
					{
						$tmp14012 .= " or charindex('{$v}',v1.Fmodel)>0 or charindex('{$v}',v1.fcustomer)>0 or charindex('{$v}',v1.fcustomerName )>0 or charindex('{$v}',v1.fmodelNO)>0 or charindex('{$v}',v1.Fbillno)>0 " ;
					}
					$keywordStr=' and ( '.trim($tmp14012,' or') .")";
				}else{
					$keywordStr=" and ( charindex('{$keyword}',v1.fmodel)>0 or charindex('{$keyword}',v1.fcustomer)>0 or charindex('{$keyword}',v1.fcustomerName )>0 or charindex('{$keyword}',v1.fmodelNO)>0 or charindex('{$keyword}',v1.fbillno )>0  ) ";
				}
			}
			
		}elseif(in_array($FRepKey, [ '14013'  ]) ){
			// 14013  -- 财务
			if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
				$keyword =  $request->keyword ;
				$keywordTmp = explode(',',$keyword);
				if(count($keywordTmp)>1){
					$tmp14013 = '';
					foreach ($keywordTmp as $v)
					{
						$tmp14013 .= " or charindex('{$v}',v1.Fmodel)>0 or charindex('{$v}',v1.fcustomer)>0 or charindex('{$v}',v1.fcustomerName )>0 or charindex('{$v}',v1.Fbillno)>0 or charindex('{$v}',v1.fmodelNO)>0" ;
					}
					$keywordStr=' and ( '.trim($tmp14013,' or') .")";
				}else{
					$keywordStr=" and ( charindex('{$keyword}',v1.fmodel)>0 or charindex('{$keyword}',v1.fcustomer)>0 or charindex('{$keyword}',v1.fcustomerName )>0 or charindex('{$keyword}',v1.fbillno )>0 or charindex('{$keyword}',v1.fmodelNO)>0 ) ";
				}
			}
			
		}elseif(in_array($FRepKey, [ '14020'  ]) ){
			// 备件信息维护
			if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
				$keyword =  $request->keyword ;
				$keywordStr=" and ( charindex('{$keyword}',u1.fbeijianName)>0 or charindex('{$keyword}',u1.fbeijianCode)>0 or charindex('{$keyword}',u1.fbeijianhao)>0 or charindex('{$keyword}',v1.fmodel)>0  ) ";
			}
			
		}elseif(in_array($FRepKey, [ '14021'  ]) ){
			// 备件信息维护
			if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
				$keyword =  $request->keyword ;
				$keywordStr=" and ( charindex('{$keyword}',v1.fbrand)>0 or charindex('{$keyword}',v1.fModel)>0  ) ";
			}
			
		}elseif(in_array($FRepKey, [ '14022' ,'14023'  ]) ){
			// 备件信息维护
			if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
				$keyword =  $request->keyword ;
				$keywordStr=" and ( charindex('{$keyword}',v1.fname)>0 or charindex('{$keyword}',v1.fcustomerno)>0    ) ";
			}
			
		}elseif($FRepKey == '12002'){
			//fcompany
			if ($request->has('fcompany') and $request->fcompany != '' and !empty($request->fcompany)) {
				$fcompanyname =  $request->fcompany ;
				$fcompanyStr=" and t1.fcompany ='{$fcompanyname}'";
			}
			if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
				$keyword =  $request->keyword ;
				$keywordStr=" and (  charindex('{$keyword}',t1.FNumber)>0  or charindex('{$keyword}',t1.FName)>0 or charindex('{$keyword}',t1.fcompany)>0 )";
	
			}
			
			if ($request->has('fdeptname') and $request->fdeptname != '' and !empty($request->fdeptname)) {
				$fdeptname =  $request->fdeptname ;
				$fdepStr=" and (sub4.fname = '{$fdeptname}' )";
			}
		}elseif(in_array($FRepKey, ['26001'   ])  ){
			//直接人工费
			if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
				$keyword =  $request->keyword ;
				$keywordStr=" and ( charindex('{$keyword}',v1.fmodel )>0  or charindex('{$keyword}',v1.Fbrand)>0 )";
			}
			if ($request->has('fbrand') and $request->fbrand != '' and !empty($request->fbrand)) {
				$fbrand =  $request->fbrand ;
				$fbrandStr=" and v1.fbrand = '{$fbrand}'  ";
			}
			
			// 26001  直接人工成本单价
			$tte = $this->getSystemProfile(['FSetRGjiegouCJPrice','FSetRGjijiaCJPrice','FSetRGzhuangshiCJPrice']);
			if(!empty($tte)){
				$fhanjiePriceStr = $tte['fsetrgjiegoucjprice'];
				$fjijiaPriceStr = $tte['fsetrgjijiacjprice'];
				$fzhuangshipriceStr = $tte['fsetrgzhuangshicjprice'];
			}
			
		}elseif(in_array($FRepKey, [  '26002'  ])  ){
			// 船检费 
			if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
				$keyword =  $request->keyword ;
				$keywordStr = " and ( charindex('{$keyword}',v1.Fmodel)>0 or charindex('{$keyword}',t2.Fbrand)>0 )";
			}
			
			if ($request->has('fchuanjishe') and $request->fchuanjishe != '' and !empty($request->fchuanjishe)) {
				$fchuanjishe =  $request->fchuanjishe ;
				$fchuanjisheStr = " and  v1.fchuanjishe = '{$fchuanjishe}' ";
			}
			if ($request->has('fbrand') and $request->fbrand != '' and !empty($request->fbrand)) {
				$fbrand =  $request->fbrand ;
				$fbrandStr = " and t2.fbrand = '{$fbrand}'  ";
			}
			
			
		}elseif(in_array($FRepKey, ['25002' ,  '25003','25004','25005' ])  ){
			// 船检费
			if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
				$keyword =  $request->keyword ;
				$keywordStr = " and ( charindex('{$keyword}',v1.Fmodel)>0 or charindex('{$keyword}',t2.Fbrand)>0 )";
			}
			
			if ($request->has('fchuanjishe') and $request->fchuanjishe != '' and !empty($request->fchuanjishe)) {
				$fchuanjishe =  $request->fchuanjishe ;
				$fchuanjisheStr = " and  v1.fchuanjishe = '{$fchuanjishe}' ";
			}
			if ($request->has('fbrand') and $request->fbrand != '' and !empty($request->fbrand)) {
				$fbrand =  $request->fbrand ;
				$fbrandStr = " and t2.fbrand = '{$fbrand}'  ";
			}
			
			
		}elseif(in_array($FRepKey, [  '25007'  ])  ){
			// 船检费 固定
			if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
				$keyword =  $request->keyword ;
				$keywordStr = " and ( charindex('{$keyword}',v1.Fmodel)>0 or charindex('{$keyword}',v1.fjybjbillno)>0)";
			}
			
			if ($request->has('fchuanjishe') and $request->fchuanjishe != '' and !empty($request->fchuanjishe)) {
				$fchuanjishe =  $request->fchuanjishe ;
				if($fchuanjishe != '全部'){
					$fchuanjisheStr = " and  v1.ftype = '{$fchuanjishe}' ";
				}
			}
			if ($request->has('fbrand') and $request->fbrand != '' and !empty($request->fbrand)) {
				$fbrand =  $request->fbrand ;
				$fbrandStr = " and t2.fbrand = '{$fbrand}'  ";
			}
			
		}elseif(in_array($FRepKey, [  '26003',  ])  ){
			//{$FSetQiGangPrice} as fCylinderoilPrice ,{$FSetZhuHunYouPrice} as v1.fMainoilprice,{$FSetRanqiPrice}
			//油气经营
			if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
				$keyword =  $request->keyword ;
				$keywordStr = " and ( charindex('{$keyword}',v1.fmodel)>0   )";
			}
			if ($request->has('fbrand') and $request->fbrand != '' and !empty($request->fbrand)) {
				$fbrand =  $request->fbrand ;
				$fbrandStr = " and v1.fbrand = '{$fbrand}'  ";
			}
			// 26001  直接人工成本单价
			$tte = $this->getSystemProfile(['FSetQiGangPrice','FSetChaiYouPrice','FSetZhuHunYouPrice','FSetRanqiPrice']);
			if(!empty($tte)){
				$FSetQiGangPriceStr = $tte['fsetqigangprice'];
				$FSetChaiYouPriceStr = $tte['fsetchaiyouprice'];
				$FSetZhuHunYouPriceStr = $tte['fsetzhuhunyouprice'];
				$FSetRanqiPriceStr =  $tte['fsetranqiprice'];
				
			}
			
		}elseif(in_array($FRepKey, [  '26007','26021'  ])  ){
			// 油气是非 ，实
			if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
				$keyword =  $request->keyword ;
				$keywordStr = " and ( charindex('{$keyword}',v1.fprodno)>0   )";
			}
			if ($request->has('fbrand') and $request->fbrand != '' and !empty($request->fbrand)) {
				$fbrand =  $request->fbrand ;
				$fbrandStr = " and v1.fbrand = '{$fbrand}'  ";
			}
		}elseif(in_array($FRepKey, [   '26004',   ])  ){
			//专利费
			if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
				$keyword =  $request->keyword ;
				$keywordStr = " and ( charindex('{$keyword}',v1.Fname)>0  or  charindex('{$keyword}',v1.fprodno)>0    )";
			}
		}elseif(in_array($FRepKey, ['26005',  ])  ){
			// 加账清单(采购)
			if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
				$keyword =  $request->keyword ;
				$keywordStr = " and ( charindex('{$keyword}',v1.Fname)>0 )";
			}
			
		}elseif(in_array($FRepKey, [  '26010',  ])  ){
			//折旧 费
			if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
				$keyword =  $request->keyword ;
				$keywordStr = " and ( charindex('{$keyword}',v1.Fname)>0 )";
			}
			if ($request->has('fyear') and $request->fyear != '' and !empty($request->fyear)) {
				$yearval =  $request->fyear ;
				$yearstr = " and  v1.fyear = '{$yearval}'  ";
			}
			
		}elseif(in_array($FRepKey, [  '26011'  ])  ){
			//水电费 
			if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
				$keyword =  $request->keyword ;
				$keywordStr=" and ( charindex('{$keyword}',v1.Fbrand)>0   or charindex('{$keyword}',v1.Fmodel)>0 )";
			}
			if ($request->has('fbrand') and $request->fbrand != '' and !empty($request->fbrand)) {
				$fbrand =  $request->fbrand ;
				$fbrandStr = " and v1.fbrand = '{$fbrand}'  ";
			}
			
		}elseif(in_array($FRepKey, [  '26014'  ])  ){
			//委外费用
			if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
				$keyword =  $request->keyword ;
				$keywordStr=" and ( charindex('{$keyword}',v1.Fbrand)>0   or charindex('{$keyword}',v1.Fmodel)>0 )";
			}
			if ($request->has('fbrand') and $request->fbrand != '' and !empty($request->fbrand)) {
				$fbrand =  $request->fbrand ;
				$fbrandStr = " and v1.fbrand = '{$fbrand}'  ";
			}
			
		}elseif(in_array($FRepKey, [  '26015'  ])  ){
			//图纸费 
			if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
				$keyword =  $request->keyword ;
				$keywordStr=" and ( charindex('{$keyword}',v1.fname)>0   or charindex('{$keyword}',v1.fbrand)>0  or charindex('{$keyword}',v1.fleixing)>0 )";
			}
			if ($request->has('fbrand') and $request->fbrand != '' and !empty($request->fbrand)) {
				$fbrand =  $request->fbrand ;
				$fbrandStr = " and v1.fbrand = '{$fbrand}'  ";
			}
			
		}elseif(in_array($FRepKey, [  '26016'  ])  ){
			// 运保费
			if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
				$keyword =  $request->keyword ;
				$keywordStr=" and ( charindex('{$keyword}',v1.Fbrand)>0   or charindex('{$keyword}',v1.Fmodel)>0 )";
			}
			if ($request->has('fbrand') and $request->fbrand != '' and !empty($request->fbrand)) {
				$fbrand =  $request->fbrand ;
				$fbrandStr = " and v1.fbrand = '{$fbrand}'  ";
			}
			
		}elseif(in_array($FRepKey, [  '26017'  ])  ){
			//特定工装
			if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
				$keyword =  $request->keyword ;
				$keywordStr=" and ( charindex('{$keyword}',v1.Fbrand)>0   or charindex('{$keyword}',v1.Fmodel)>0 )";
			}
			if ($request->has('fbrand') and $request->fbrand != '' and !empty($request->fbrand)) {
				$fbrand =  $request->fbrand ;
				$fbrandStr = " and v1.fbrand = '{$fbrand}'  ";
			}
			
		}elseif(in_array($FRepKey, [  '26018'  ])  ){
			//特定刀具
			if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
				$keyword =  $request->keyword ;
				$keywordStr=" and ( charindex('{$keyword}',v1.Fbrand)>0   or charindex('{$keyword}',v1.Fmodel)>0 )";
			}
			if ($request->has('fbrand') and $request->fbrand != '' and !empty($request->fbrand)) {
				$fbrand =  $request->fbrand ;
				$fbrandStr = " and v1.fbrand = '{$fbrand}'  ";
			}
			
		}elseif(in_array($FRepKey, [  '26019'  ])  ){
			// 排放测试费 
			if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
				$keyword =  $request->keyword ;
				$keywordStr=" and ( charindex('{$keyword}',v1.Fname)>0   or charindex('{$keyword}',v1.Fmodel)>0 )";
			}
			
		}elseif(in_array($FRepKey, [  '26020'  ])  ){
			// 图纸送审费
			if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
				$keyword =  $request->keyword ;
				$keywordStr=" and ( charindex('{$keyword}',v1.Fbrand)>0   or charindex('{$keyword}',v1.Fmodel)>0 )";
			}
			if ($request->has('fbrand') and $request->fbrand != '' and !empty($request->fbrand)) {
				$fbrand =  $request->fbrand ;
				$fbrandStr = " and v1.fbrand = '{$fbrand}'  ";
			}
			
		}elseif(in_array($FRepKey, [  '26024'  ])  ){
			// 船检费 固定
			if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
				$keyword =  $request->keyword ;
				$keywordStr = " and ( charindex('{$keyword}',v1.Fmodel)>0 or charindex('{$keyword}',v1.fjybjbillno)>0)";
			}
			
			if ($request->has('fchuanjishe') and $request->fchuanjishe != '' and !empty($request->fchuanjishe)) {
				$fchuanjishe =  $request->fchuanjishe ;
				if($fchuanjishe != '全部'){
					$fchuanjisheStr = " and  v1.ftype = '{$fchuanjishe}' ";
				}
				
			}
			if ($request->has('fbrand') and $request->fbrand != '' and !empty($request->fbrand)) {
				$fbrand =  $request->fbrand ;
				$fbrandStr = " and t2.fbrand = '{$fbrand}'  ";
			}
			
		}elseif(in_array($FRepKey, [   '26012', '26013'  ])  ){
			//质量成本 -- 26013  , 售后维护成本 -- 26012
			if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
				$keyword =  $request->keyword ;
				$keywordStr=" and ( charindex('{$keyword}',v1.Fbrand)>0   or charindex('{$keyword}',v1.Fmodel)>0 )";
			}
			if ($request->has('fbrand') and $request->fbrand != '' and !empty($request->fbrand)) {
				$fbrand =  $request->fbrand ;
				$fbrandStr = " and v1.fbrand = '{$fbrand}'  ";
			}
			 
		}elseif(in_array($FRepKey, [ '26008' , '28006', '28007'  ])  ){
			// 辅材成本 结构 26008，   辅材成本机加工  28006，   辅材成本 装试 28007， 
			if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
				$keyword =  $request->keyword ;
				$keywordStr=" and ( charindex('{$keyword}',v1.Fbrand)>0   or charindex('{$keyword}',v1.Fmodel)>0 )";
			}
			if ($request->has('fbrand') and $request->fbrand != '' and !empty($request->fbrand)) {
				$fbrand =  $request->fbrand ;
				$fbrandStr = " and v1.fbrand = '{$fbrand}'  ";
			}
			
		}elseif(in_array($FRepKey, [  '26022', '26009',   ])  ){
			if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
				$keyword =  $request->keyword ;
				$keywordStr=" and ( charindex('{$keyword}',v1.Fname)>0 or charindex('{$keyword}',v1.fprodno)>0      )";
			}
		}elseif(in_array($FRepKey, ['27001' ,'27002','27003','27004','27005','27006','27008','27009','27012','27013', '27014','27015'  ])  ){
			// SCR/EGR油气非首台  -- 27008 
			if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
				$keyword =  $request->keyword ;
				$keywordStr=" and (   charindex('{$keyword}',v1.fmodel)>0  or   charindex('{$keyword}',v1.fbillno)>0  )";
			}
			
		}elseif(in_array($FRepKey, [ '27010'  , '27011' ])  ){
			// 27010  , 27011 --  ICER数据库信息(技术)
			if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
				$keyword =  $request->keyword ;
				$keywordStr=" and (   charindex('{$keyword}',v1.fEGCModel)>0      )";
			}
			
		}elseif(in_array($FRepKey, [ '27007'  ])  ){
			// ICER管件类采购成本  -- 27007
			if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
				$keyword =  $request->keyword ;
				$keywordStr=" and (   charindex('{$keyword}',v1.fmodel)>0  or  charindex('{$keyword}',v1.fbillno)>0     )";
			}
			 
		}elseif(in_array($FRepKey, [  '29001'  ])  ){
			//燃油汇总
			if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
				$keyword =  $request->keyword ;
				$keywordStr=" and (   charindex('{$keyword}',v1.fmodel)>0 or  charindex('{$keyword}',v1.fbillno)>0       )";
			}
			//选择燃油 1 
			$fisranyouhzTmp = $request->fisranyouhz ;
			if (  $request->fisranyouhz == 1 ) {
				$fisranyouhzStr=" and (   charindex('LGIM',v1.fmodel)= 0  )";
			}elseif( $request->fisranyouhz == 2){
				$fisranyouhzStr=" and (   charindex('LGIM',v1.fmodel)> 0   )";
			}
			
			 
			
		}elseif(in_array($FRepKey, ['30002' , '30003' ])){
			//预算成本 30002   
			if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
				$keyword =  $request->keyword ;
				$keywordTmp = explode(',',$keyword);
				if(count($keywordTmp)>1){
					$tmp30002 = '';
					foreach ($keywordTmp as $v)
					{
						$tmp30002 .= " or charindex('{$v}',v1.Fmodel)>0 or charindex('{$v}',v1.Fbillno)>0  or charindex('{$v}',u1.fcustomer)>0 or charindex('{$v}',u1.fcustomerName)>0  or charindex('{$v}',u1.fmodelNO)>0 " ;
					}
					$keywordStr=' and ( '.trim($tmp30002,' or') .")";
				}else{
					$keywordStr=" and ( charindex('{$keyword}',v1.Fmodel)>0 or charindex('{$keyword}',v1.Fbillno)>0 or charindex('{$keyword}',u1.fcustomer)>0 or charindex('{$keyword}',u1.fcustomerName)>0 or charindex('{$keyword}',u1.fmodelNO)>0  )";
				}
			}
			// 正式报价-- 已完成 5 
			if($request->fstatus == 5 && $FRepKey == '30002' ){
				$wanchengStr = " and  v1.fisqr = 1  ";
			}
			
			if($request->tkkey == '50001' && $FRepKey == '30002' ){
				$fenXiStr = "  and  not EXISTS ( SELECT fbillno FROM gz_Yfenxibiao hz where 1 = 1 and v1.fbillno = hz.fbillno ) ";
			}
			
		}elseif(in_array($FRepKey, [ '30004'  ])){
			if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
				$keyword =  $request->keyword ; 
				$keywordTmp = explode(',',$keyword);
				if(count($keywordTmp)>1){
					$tmp30004 = '';
					foreach ($keywordTmp as $v)
					{
						$tmp30004 .= " or charindex('{$v}',v1.Fmodel)>0 or charindex('{$v}',v1.Fbillno)>0  " ;
					}
					$keywordStr=' and ( '.trim($tmp30004 ,' or') .")";
				}else{
					$keywordStr=" and ( charindex('{$keyword}',v1.Fmodel)>0 or charindex('{$keyword}',v1.Fbillno)>0  )";
				}
			}
			// 经营报价-- 已完成 5
			if($request->fstatus == 5 && $FRepKey == '30004' ){
				$wanchengStr = " and  v1.fisqr = 1  ";
			}
			
		}elseif(in_array($FRepKey, [  '30005', '30006', '30007', '30008' ])){
			//走流程  30004  , 走流程机型(技术)30005 , 走流程机型(采购) 30006, 走流程机型(财务)30007 , 走流程机型(业务)30008
			if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
				$keyword =  $request->keyword ;
				$keywordStr=" and ( charindex('{$keyword}',v1.Fmodel)>0  or charindex('{$keyword}',v1.fbillno)>0  )";
			}
			
		}elseif(in_array($FRepKey, ['30009' ,])){
			//预算成本
			if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
				$keyword =  $request->keyword ;
				$keywordTmp = explode(',',$keyword);
				if(count($keywordTmp)>1){
					$tmpcx = '';
					foreach ($keywordTmp as $v)
					{
						$tmpcx .= " or charindex('{$v}',v1.Fmodel)>0 " ;
					}
					$keywordStr=' and ( '.trim($tmpcx ,' or') .")";
				}else{
					$keywordStr=" and ( charindex('{$keyword}',v1.fmodel)>0 ) ";
				}
				 
			}
			if ($request->has('brand') and $request->brand != '' and !empty($request->brand)) {
				$fbrand =  $request->brand ;
				$fbrandStr=" and v1.fbrand = '{$fbrand}'";
			}
			
		}elseif(in_array($FRepKey, ['30010' ,])){
			// 后续
			if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
				$keyword =  $request->keyword ;
				$keywordStr=" and ( charindex('{$keyword}',v1.fmodel)>0 or charindex('{$keyword}',v1.fcustomer)>0 or charindex('{$keyword}',v1.fcustomerName )>0  or charindex('{$keyword}',v1.fmodelNO )>0 or charindex('{$keyword}',v1.fbillno )>0 or charindex('{$keyword}',v1.fbillnoentry )>0  ) ";
				
			}
			
		}elseif(in_array($FRepKey, ['30011' ,])){
			// 后续
			if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
				$keyword =  $request->keyword ;
				$keywordTmp = explode(',',$keyword);
				if(count($keywordTmp)>1){
					$tmp30011 = '';
					foreach ($keywordTmp as $v)
					{
						$tmp30011 .= " or charindex('{$v}',v1.Fmodel)>0 or charindex('{$v}',v1.Fbillno)>0 or charindex('{$v}',v1.fbillnoentry )>0 or charindex('{$v}',u1.fcustomer)>0 or charindex('{$v}',u1.fcustomerName)>0  or charindex('{$v}',u1.fmodelNO)>0 " ;
					}
					$keywordStr=' and ( '.trim($tmp30011 ,' or') .")";
				}else{
					$keywordStr=" and ( charindex('{$keyword}',v1.Fmodel)>0 or charindex('{$keyword}',v1.Fbillno)>0  or charindex('{$keyword}',v1.fbillnoentry )>0 or charindex('{$keyword}',u1.fcustomer)>0 or charindex('{$keyword}',u1.fcustomerName)>0 or charindex('{$keyword}',u1.fmodelNO)>0  )";
				}
				
			}
			if ($request->has('brand') and $request->brand != '' and !empty($request->brand)) {
				$fbrand =  $request->brand ;
				$fbrandStr=" and v1.fbrand = '{$fbrand}'";
			}
			// 后续报价-- 已完成 5
			if($request->fstatus == 5 && $FRepKey == '30011' ){
				$wanchengStr = " and  v1.fisqr = 1  ";
			}
			
		}elseif(in_array($FRepKey, ['34004'  ])){
			// 正式报价加账
			if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
				$keyword =  $request->keyword ;
				$keywordTmp = explode(',',$keyword);
				if(count($keywordTmp)>1){
					$tmp34004 = '';
					foreach ($keywordTmp as $v)
					{
						$tmp34004 .= " or charindex('{$v}',v1.Fmodel)>0 or charindex('{$v}',v1.Fbillno)>0 or charindex('{$v}',v1.fbillnoentry )>0 or charindex('{$v}',u1.fcustomer)>0 or charindex('{$v}',u1.fcustomerName)>0  or charindex('{$v}',u1.fmodelNO)>0" ;
					}
					$keywordStr=' and ( '.trim($tmp34004 ,' or') .")";
				}else{
					$keywordStr=" and ( charindex('{$keyword}',v1.Fmodel)>0 or charindex('{$keyword}',v1.Fbillno)>0 or charindex('{$keyword}',v1.Fbillnoentry)>0  or charindex('{$keyword}',u1.fcustomer)>0 or charindex('{$keyword}',u1.fcustomerName)>0 or charindex('{$keyword}',u1.fmodelNO)>0 )";
				}
			}
			if($request->fstatus == 5 && $FRepKey == '34004' ){
				$wanchengStr = " and  v1.fisqr = 1  ";
			}
			
		}elseif(in_array($FRepKey, [   '34001','34002', '34003', '34005' ])){
			//  正式报价加账
			if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
				$keyword =  $request->keyword ;
				$keywordStr=" and ( charindex('{$keyword}',v1.Fmodel)>0 or charindex('{$keyword}',v1.Fbillno)>0 or charindex('{$keyword}',v1.Fbillnoentry)>0   or charindex('{$keyword}',v1.fcustomer)>0  or charindex('{$keyword}',v1.fcustomerName)>0  or charindex('{$keyword}',v1.fmodelNO)>0	 )";
			}
			
		}elseif(in_array($FRepKey, [  '40001','40002','40004','40005',  ])  ){
			//备件 
			if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
				$keyword =  $request->keyword ;
				$keywordStr=" and ( charindex('{$keyword}',v1.Fmodel)>0 or charindex('{$keyword}',v1.Fbillno)>0 or charindex('{$keyword}',u1.fbeijianName)>0 
				 or charindex('{$keyword}',u1.fbeijianCode)>0  or charindex('{$keyword}',u1.fbeijianhao)>0  or  charindex('{$keyword}',v1.fcustomer)>0 or  charindex('{$keyword}',v1.fprodectNO)>0)";
			}
			
		}elseif(in_array($FRepKey, [  '50001',   ])  ){
			//报表分析
			if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
				$keyword =  $request->keyword ;
				$keywordTmp = explode(',',$keyword);
				if(count($keywordTmp)>1){
					$tmp50001 = '';
					foreach ($keywordTmp as $v)
					{
						$tmp50001 .= " or charindex('{$v}',v1.Fmodel)>0 or charindex('{$v}',v1.Fbillno)>0 or charindex('{$v}',v1.fcustomerno )>0 or charindex('{$v}',v1.fcustomernols )>0 " ;
					}
					$keywordStr=' and ( '.trim($tmp50001 ,' or') .")";
				}else{
					$keywordStr=" and ( charindex('{$keyword}',v1.Fmodel)>0 or charindex('{$keyword}',v1.Fbillno)>0 or charindex('{$keyword}',v1.fcustomerno)>0  or charindex('{$keyword}',v1.fcustomernols)>0   )";
				}
			}
			
		}else{
			if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
				$keyword =  $request->keyword ;
				$keywordStr=" and (  charindex('{$keyword}',t1.FNumber)>0  or charindex('{$keyword}',t1.FName)>0 or charindex('{$keyword}',t1.fcompany)>0 )";
			}
			
			if ($request->has('fdeptname') and $request->fdeptname != '' and !empty($request->fdeptname)) {
				$fdeptname =  $request->fdeptname ;
				$fdepStr=" and (sub4.fname = '{$fdeptname}' )";
			}
			
			if ($request->has('fcompany') and $request->fcompany != '' and !empty($request->fcompany)) {
				$fcompanyname =  $request->fcompany ;
				$fcompanyStr=" and t1.fcompany ='{$fcompanyname}'";
			}
			
			$patten = "/^[1-9]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/";
			if ($request->has('start_time') and $request->start_time != '' and $request->start_time != 'null') {
				if($request->has('end_time') and $request->end_time != '' and $request->end_time != 'null'){
					if(preg_match($patten,$request->end_time))
					{
						$etime = $request->end_time;
					}else{
						showMsg(400,'结束时间格式不正确');
					}
				}
				if(preg_match($patten,$request->start_time))
				{
					$stime = $request->start_time;
					$dateStr="and t1.FHireDate >='{$stime}' and  t1.FHireDate<= '{$etime}' "	;
				}else{
					showMsg(400,'时间格式不正确');
				}
			}
			 
		}
		
		//品牌 
		if(in_array($FRepKey, ['30001' ,'30002' ,'30003' ,'30004' , '30005' ,'30006' ,'30007' ,'30008' ,   ])){
			if ($request->has('brand') and $request->brand != '' and !empty($request->brand)) {
				$fbrand =  $request->brand ;
				$fbrandStr=" and v1.fbrand = '{$fbrand}'";
			}
		}
		
		//备件    1-- 未报价 , 3-- 已报价 ,0 --全部 
		 if(in_array($FRepKey, ['40001'  ])){
			$ftypecheck = $request->ftypecheck??0 ;
			if (  $ftypecheck == 3) {
				//已报价
				$baojiaStr= " and v1.ftypecheck = 4";
			} elseif( $ftypecheck == 1){
				//未报价
				$baojiaStr= " and ( v1.ftypecheck in (0,1,2,3) ) ";
			}elseif( $ftypecheck == 5){
				//已完成
				$baojiaStr= " and ( v1.ftypecheck = 5   ) ";
			}
			
		}
		//备件 技术 
		if(in_array($FRepKey, ['40002'  ])){
			$ftypecheck = $request->ftypecheck??0 ;
			if (  $ftypecheck == 3) {
				//已报价
				$baojiaStr= " and v1.ftypecheck = 4";
			}elseif( $ftypecheck == 1){
				//未报价
				$baojiaStr= " and ( v1.ftypecheck  in (1 ,2,3)   ) ";
			}elseif( $ftypecheck == 5){
				//已完成
				$baojiaStr= " and ( v1.ftypecheck = 5   ) ";
			}
			
			
		}
		//备件采购 -- 
		if(in_array($FRepKey, ['40004'  ])){
			$ftypecheck = $request->ftypecheck??0 ;
			if (  $ftypecheck == 3) {
				//已报价
				$baojiaStr= " and v1.ftypecheck = 4";
			}elseif( $ftypecheck == 1){
				//未报价
				$baojiaStr= " and ( v1.ftypecheck in (1, 2,3)  ) ";
			}elseif( $ftypecheck == 5){
				//已完成
				$baojiaStr= " and ( v1.ftypecheck = 5   ) ";
			}
			
			
		}
		//备件 财务 -- 
		if(in_array($FRepKey, ['40005'  ])){
			$ftypecheck = $request->ftypecheck??0 ;
			if (  $ftypecheck == 3) {
				//已报价
				$baojiaStr= " and v1.ftypecheck = 4";
			}elseif( $ftypecheck == 1){
				//未报价
				$baojiaStr= " and ( v1.ftypecheck = 3   ) ";
			}elseif( $ftypecheck == 5){
				//已完成
				$baojiaStr= " and ( v1.ftypecheck = 5   ) ";
			}
		}
		
		
		//业务  --流程确认
		if(in_array($FRepKey, ['14011' ])){
			if($request->fisqr == 0 ){
				//未确认
				$fisqrStr = " and v1.fisqr in (0,1, 2)";
			}elseif($request->fisqr == 5){
				//已完成
				$fisqrStr = " and u1.fisqr = 1";
			}else{
				//已确认 
				$fisqrStr = " and v1.fisqr in ( 3)  and isnull(u1.fisqr,0) = 0 ";
			}
		}
		
		if(in_array($FRepKey, [ '14012'  ])){
			if($request->fisqr == 0 ){
				//未确认
				$fisqrStr = " and v1.fisqr in ( 0,1,2) ";
			}elseif($request->fisqr == 5){
				//已完成
				$fisqrStr = " and u1.fisqr = 1";
			}else{
				//已确认
				$fisqrStr = " and v1.fisqr in ( 3 ) and isnull(u1.fisqr,0) = 0 ";
			}
		}
		
		if(in_array($FRepKey, [ '14013'  ])){
			if($request->fisqr == 0 ){
				//未确认
				$fisqrStr = " and v1.fisqr in (0, 1,2) ";
			} elseif($request->fisqr == 5){
				//已完成
				$fisqrStr = " and u1.fisqr = 1";
			}else{
				//已确认
				$fisqrStr = " and v1.fisqr = 3 and isnull(u1.fisqr,0) = 0 ";
			}
		}
		
		
		//正式加账 --业务 34001
		if(in_array($FRepKey, ['34001' ])){
			if($request->fisqr == 0 ){
				//未确认0
				$fisqrStr = " and v1.fisqr in (0,1, 2)";
			}elseif($request->fisqr == 2){
				//已确认2
				$fisqrStr = " and v1.fisqr in ( 3) and isnull(u1.fisqr,0) = 0 ";
			}
		}
		//加账 --技术 34002
		if(in_array($FRepKey, [ '34002'  ])){
			if($request->fisqr == 0 ){
				//未确认0
				$fisqrStr = " and v1.fisqr in ( 0,1,2) ";
			}elseif($request->fisqr == 5){
				//已完成5
				$fisqrStr = " and u1.fisqr = 1";
			}else{
				//已确认2
				$fisqrStr = " and v1.fisqr in ( 3 ) and isnull(u1.fisqr,0) = 0 ";
			}
		}
		//加账 --采购 34003
		if(in_array($FRepKey, [ '34003'  ])){
			if($request->fisqr == 0 ){
				//未确认
				$fisqrStr = " and v1.fisqr in (0, 1,2) ";
			}elseif($request->fisqr == 5){
				//已完成
				$fisqrStr = " and u1.fisqr = 1";
			}else{
				//已确认
				$fisqrStr = " and v1.fisqr = 3 and isnull(u1.fisqr,0) = 0 ";
			}
		}
		
		//加账 --财务  34005  
		if(in_array($FRepKey, [ '34005'  ])){
			if($request->fisqr == 0 ){
				//未确认
				$fisqrStr = " and v1.fisqr in (0, 1,2) ";
			}elseif($request->fisqr == 5){
				//已完成
				$fisqrStr = " and u1.fisqr = 1";
			}else{
				//已确认
				$fisqrStr = " and v1.fisqr = 3 and isnull(u1.fisqr,0) = 0 ";
			}
		}
	 
		
		//经营报价  -- 技术
		if(in_array($FRepKey, [ '30005'  ])){
			if($request->fisqr == 0 ){
				//未确认
				$fisqrStr = " and v1.fisqr in ( 0,1,2) ";
			}elseif($request->fisqr == 5){
				//已完成
				$fisqrStr = " and u1.fisqr = 1";
			}else{
				//已确认
				$fisqrStr = " and v1.fisqr in ( 3 ) and  isnull(u1.fisqr,0) = 0 ";
			}
		}
		//走流程  --采购
		if(in_array($FRepKey, [ '30006'  ])){
			if($request->fisqr == 0 ){
				//未确认
				$fisqrStr = " and v1.fisqr in (0, 1,2) ";
			}elseif($request->fisqr == 5){
				//已完成
				$fisqrStr = " and u1.fisqr = 1";
			}else{
				//已确认
				$fisqrStr = " and v1.fisqr in ( 3 ) and isnull(u1.fisqr,0) = 0 ";
			}
		}
		 //走流程  --财务 
		if(in_array($FRepKey, [ '30007'  ])){
			if($request->fisqr == 0 ){
				//未确认
				$fisqrStr = " and v1.fisqr in ( 0,1,2) ";
			}elseif($request->fisqr == 5){
				//已完成
				$fisqrStr = " and u1.fisqr = 1";
			}else{
				//已确认
				$fisqrStr = " and v1.fisqr = 3 and isnull(u1.fisqr,0) = 0 ";
			}
		}
		//走流程  --业务 
		if(in_array($FRepKey, [ '30008'  ])){
			if($request->fisqr === 0 ){
				//未确认
				$fisqrStr = " and v1.fisqr in ( 0,1,2) ";
			}elseif($request->fisqr == 5){
				//已完成
				$fisqrStr = " and u1.fisqr = 1";
			}elseif($request->fisqr == 2){
				//已确认
				$fisqrStr = " and v1.fisqr = 3 and isnull(u1.fisqr,0) = 0 ";
			}
		}
		
		
		
		
		$fstatusStr = '';
		if($FRepKey != '12001'){
			$fstatus = $request->fstatus?$request->fstatus:0;
			if($fstatus == 1){
				//未审核 1
				$fstatusStr = " and v1.fstatus = 0";
			}elseif($fstatus == 2){
				//审核 2
				$fstatusStr = " and v1.fstatus = 1";
			}elseif($fstatus == 5){
				if($FRepKey == '14009'){
					//已完成
					$fstatusStr = " and u1.fisqr = 1";
				}
				if($FRepKey == '34001'){
					//已完成
					$fstatusStr = " and u1.fisqr = 1";
				}
				if($FRepKey == '30010'){
					//已完成
					$fstatusStr = " and u1.fisqr = 1";
				}
				if($FRepKey == '30008'){
					//已完成
					$fstatusStr = " and u1.fisqr = 1";
				}
			}elseif($fstatus == 4){
				//已完成
				$fstatusStr = " and v1.fqrJS <> '' and v1.fqrCG <>'' and v1.fqrCW = '' ";
			}
		}
		
		$ffustatusStr = '';
		if($FRepKey == '12011'){
			$ffustatus = $request->ffustatus?$request->ffustatus:0;
			if($ffustatus == 1){
				//未审核 1
				$ffustatusStr = " and v1.ffustatus = 0";
			}elseif($ffustatus == 2){
				//审核 2
				$ffustatusStr = " and v1.ffustatus = 1";
			}
		}
		
		$fstatuscgStr = '';
		if($FRepKey == '27011'){
			$fstatuscg = $request->fstatuscg?$request->fstatuscg:0;
			if($fstatuscg == 1){
				//未审核 1
				$fstatuscgStr = " and v1.fstatuscg = 0";
			}elseif($fstatuscg == 2){
				//审核 2
				$fstatuscgStr = " and v1.fstatuscg = 1";
			}
		}
		
		
		
		$fdeletedStr='';
		if($request->fdeleted == 1){
			$fdeletedStr=" and sub5.fname = '在职'";
		}elseif($request->fdeleted == 2){
			$fdeletedStr=" and sub5.fname ='自离'";
		}elseif($request->fdeleted == 3){
			$fdeletedStr=" and sub5.fname = '辞职未发放' ";
		}elseif($request->fdeleted == 4){
			$fdeletedStr=" and sub5.fname = '请长假' ";
		}elseif($request->fdeleted ==5){
			$fdeletedStr=" and sub5.fname = '辞职已发放' ";
		}elseif($request->fdeleted == 6){
			$fdeletedStr=" and sub5.fname = '已补发' ";
		}elseif($request->fdeleted == 7){
			$fdeletedStr=" and sub5.fname = '待辞职'";
		}
		
	 
		//年度 期间 qjValue
		$Year ='';
		$Month='';
		
		$syYear ='';
		$syMonth='';
		
		$syglYear ='';
		$syglMonth='';
		if($request->has('qjValue') && $request->qjValue != '' && !empty($request->qjValue) && $request->qjValue != 'null'){
			list($year,$mon) = explode('-',$request->qjValue);
			$timeStr .=" and v1.FYear = '{$year}'";
			$Year = $year;
			$mon = intval($mon);
			$timeStr .=" and v1.FPeriod = '{$mon}'";
			$Month =$mon;
			
			if($mon == 1){
				$year1= $year-1;
				$syYear = " and v2.FYear = '{$year1}' ";
				$syMonth= " and v2.FPeriod = 12 " ;
				
				$syglYear= $year1;
				$syglMonth= 12;
			}else{
				$mon1= $mon-1;
				$syYear = " and v2.FYear = '{$year}' "; 
				$syMonth= " and v2.FPeriod = {$mon1} " ;
				$syglYear= $year;
				$syglMonth= $mon1;
			}
		}
		
		$db = columnBiao($FRepKey);//表名
		//获取文件getfileSql
		$sqlData = getfileSql($FRepKey);
		if(!$sqlData){
			showMsg(1,'设置Sql不存在');
		}
		$sql= $sqlData ;
		$vowels = array("\n", "\r", "\t");
 
		$sql = str_replace($vowels, ' ',$sql);
		//做变量替换
		$sql = str_replace('{$keyword}', $keywordStr, $sql);
		$sql = str_replace('{$timeStr}', $timeStr, $sql);
		$sql = str_replace('{$Year}', $Year, $sql);
		$sql = str_replace('{$Month}', $Month, $sql);
		$sql = str_replace('{$appStr}', $appStr, $sql);
		$sql = str_replace('{$dateStr}', $dateStr, $sql);
		
		$sql = str_replace('{$fbatchno}', $fbatchnoStr, $sql);
		$sql = str_replace('{$fcompany}', $fcompanyStr, $sql);
		$sql = str_replace('{$fstatus}', $fstatusStr, $sql);
		$sql = str_replace('{$ffustatus}', $ffustatusStr, $sql);
		
		$sql = str_replace('{$syYear}', $syYear, $sql);
		$sql = str_replace('{$syMonth}', $syMonth, $sql);
		
		$sql = str_replace('{$syglYear}', $syglYear, $sql);
		$sql = str_replace('{$syglMonth}', $syglMonth, $sql);
		$sql = str_replace('{$fdeleted}', $fdeletedStr, $sql);
		$sql = str_replace('{$fdepStr}', $fdepStr, $sql);
		$sql = str_replace('{$fcategoryStr}', $fcategoryStr, $sql);
		//船级社
		$sql = str_replace('{$fchuanjishe}', $fchuanjisheStr, $sql);
		//品牌
		$sql = str_replace('{$fbrandstr}', $fbrandStr, $sql);
		//备件报价 
		$sql = str_replace('{$baojiastr}', $baojiaStr, $sql);
		//成本 部门
		$sql = str_replace('{$cbbumenstr}', $cbbumenstr, $sql);
		//业务部门需求
		$sql = str_replace('{$fisqrstr}', $fisqrStr, $sql);
		//折旧 年度
		$sql = str_replace('{$yearstr}', $yearstr, $sql);
		// ICER数据库信息 - 采购
		$sql = str_replace('{$fstatuscg}', $fstatuscgStr, $sql);
		
		//直接人工单价
		$sql = str_replace('{$fhanjiePrice}', $fhanjiePriceStr, $sql);
		$sql = str_replace('{$fjijiaPrice}', $fjijiaPriceStr, $sql);
		$sql = str_replace('{$fzhuangshiprice}', $fzhuangshipriceStr, $sql);
		
		//燃油单价
		$sql = str_replace('{$FSetQiGangPrice}', $FSetQiGangPriceStr, $sql); // 气缸油
		$sql = str_replace('{$FSetChaiYouPrice}', $FSetChaiYouPriceStr, $sql); //柴油
		$sql = str_replace('{$FSetZhuHunYouPrice}', $FSetZhuHunYouPriceStr, $sql); //主滑油
		$sql = str_replace('{$FSetRanqiPrice}', $FSetRanqiPriceStr, $sql); //燃气
		//加账SCR/ICER管理
		$sql = str_replace('{$scregrstr}', $scrEgrStr, $sql);  
		//燃油汇总 
		$sql = str_replace('{$ranyouhzstr}', $ranyouHzStr, $sql);  
		//分析报表弹框 
		$sql = str_replace('{$fenxistr}', $fenXiStr, $sql);  
		//正式 已完成 
		$sql = str_replace('{$wanchengstr}', $wanchengStr, $sql);  
		//甲醇磨合调整 弹框 显示 
		$sql = str_replace('{$jiachunstr}', $jiachunStr, $sql);  
		//燃油汇总
		$sql = str_replace('{$fisranyouhzstr}', $fisranyouhzStr, $sql);  
		//船级社其他设置 
		$sql = str_replace('{$chuanjisheqtstr}', $chuanjisheQTStr, $sql);  
		
// 		echo $sql ;die; 
		$newsql = $sql;
		$sql=" select top $limit * from ( $sql ) temp_row where rownumber>(($page-1)*$limit)";
// 		echo $sql ;die; 
		
		$res = SqlServerUtil::exec1($this->SqlServer,$sql);
		if($res === false){
// 			showMsg(1,'设置Sql错误重新编辑！');
			$res =[];
		}
		
		$result =[];
		if($res){
			$result = arraykeyToLower($res);
			foreach ($result as $k => &$v)
			{
				foreach ($v as $k1=>$v1)
				{
					if( $v[$k1] ==='.00' || ( ($v[$k1]>0 && $v[$k1]<1) && $k1 !='fzhujiranliaos' ) ){
						$v[$k1] = floatval($v1);
					}
				}
			}
		}
		
// 		dd($result);
		$datasql = substr( $newsql ,stripos($newsql ,' from')+5  );
 
		$datasql = iconv( 'UTF-8','GBK',$datasql);
		
		$countSql ="SELECT COUNT(1) AS total FROM  {$datasql} ";
		$count = SqlServerUtil::exec($this->SqlServer, $countSql);
		$total = !empty($count[0]['total']) ? $count[0]['total']:0; 
		$this->response['total'] = $total;
		$this->response['size'] = 1;
		$last_page = 0;
		if($count && count($count)>0){
			$last_page = !empty($total) ? ceil($total/$limit):0;
			$this->response['size'] = $limit;
		}
		
		$this->response['Data'] = $result;
		$this->response['cur_page'] =$page;
		$this->response['last_page'] =$last_page;
		return response()->json($this->response);
	}
	
	/**
	* 聚一科技 ^_^   
	* @date: 2020年9月9日
	* @author: lq
	* @version:App V2.0
	*/
	public function finishList(Request $request){
		$timeStr='';
		$fgxnameStr='';
		$fbillnoStr='';
		$jtnumberStr= '';
		$fzynameStr='';
		$fhelpcodeStr='';
		$wlfnumberStr='';
		
		$page= $request ->get('page');
		if(!isset($page)) $page =1;
		$limit= $request ->get('limit');
		if(!isset($limit)) $limit =20;
		$pages = ($page-1)* $limit;
		//时间
		$patten = "/^[1-9]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/";
		if ($request->has('start_time') and $request->start_time != '' and $request->start_time != 'null') {
			if($request->has('end_time') and $request->end_time != '' and $request->end_time != 'null'){
				if(preg_match($patten,$request->end_time))
				{
					$etime = $request->end_time;
				}else{
					showMsg(400,'结束时间格式不正确');
				}
			}
			if(preg_match($patten,$request->start_time))
			{
				$stime = $request->start_time;
				$timeStr="and t1.FDateSC >='{$stime} 00:00:00' and t1.FDateSC<='{$etime} 23:59:59' "	;
			}else{
				showMsg(400,'时间格式不正确');
			}
		}
		//工序名称/代码
		if ($request->has('fgxname') and $request->fgxname != '' and !empty($request->fgxname)) {
			$fgxname = $request->fgxname;
			$fgxname =iconv('UTF-8', 'GBK', $fgxname);
			$fgxnameStr=" and (tic2.FName  like '%{$fgxname}%' or tic2.FNumber like '%{$fgxname}%' )";
		}
		//系统单号
		if ($request->has('fbillno') and $request->fbillno != '' and !empty($request->fbillno)) {
			$fbillno = $request->fbillno;
			$fbillno =iconv('UTF-8', 'GBK', $fbillno);
			$fbillnoStr=" and v1.fbillno like '%{$fbillno}%'";
		}
		//wuliao编号
		if ($request->has('wlfnumber') and $request->wlfnumber != '' and !empty($request->wlfnumber)) {
			$wlfnumber = $request->wlfnumber;
			$wlfnumber =iconv('UTF-8', 'GBK', $wlfnumber);
			$wlfnumberStr=" and tic2.fnumber like '%{$wlfnumber}%'";
		}
		//图号
		if ($request->has('fhelpcode') and $request->fhelpcode != '' and !empty($request->fhelpcode)) {
			$fhelpcode = $request->fhelpcode;
			$fhelpcode =iconv('UTF-8', 'GBK', $fhelpcode);
			$fhelpcodeStr=" and tic2.FHelpCode like '%{$fhelpcode}%'";
		}
		//机台号
		if ($request->has('jtnumber') and $request->jtnumber != '' and !empty($request->jtnumber)) {
			$jtnumber = $request->jtnumber;
			$jtnumber =iconv('UTF-8', 'GBK', $jtnumber);
			$jtnumberStr=" and t1.FEntryText1 ='{$jtnumber}'";
		}
		//工序职员
		if ($request->has('fzyname') and $request->fzyname != '' and !empty($request->fzyname)) {
			$fzyname = $request->fzyname;
			$fzyname =iconv('UTF-8', 'GBK', $fzyname);
			$fzynameStr=" and (tem.fname like '%{$fzyname}%' or tem.Fnumber like '%{$fzyname}%')";
		}
		
		$sql ="select top $limit * from (SELECT
		row_number() over(order by t1.FID desc) as rownumber,
		t1.*
,tsup.FNumber as fsupplyidnumber,tsup.FName as fsupplyidname
,(t1.Fqtylp*tic2.fplanprice + t1.FHourAmount + t1.FConsignAmount + t1.FJBHourAmount+t1.fbtamount) as FSumAmount
,tic2.FModel,tdp.FName as fdeptidname
from gz_ICMakeFlowEntryMX t1 
inner join t_icitem tic2 on t1.FItemIDNumber = tic2.FNumber 
LEFT join t_emp tem on tem.FNumber = t1.FEmpCode
LEFT join t_Department tdp on tdp.FItemID = tem.FDepartmentID 
LEFT join t_Supplier tsup on tsup.FItemID = t1.FSupplyID  where 2=2 {$timeStr} {$fgxnameStr} {$fbillnoStr} {$jtnumberStr} {$fzynameStr} {$fhelpcodeStr} {$wlfnumberStr} ) temp_row
		where rownumber>(($page-1)*$limit)";
		
		
		$res = SqlServerUtil::exec($this->SqlServer, $sql);
		if($res === false)
		{
			showMsg(400,'服务器报错');
		}
		
		$sqlcount ="SELECT count(*) count from gz_ICMakeFlowEntryMX t1 
inner join t_icitem tic2 on t1.FItemIDNumber = tic2.FNumber 
LEFT join t_emp tem on tem.FNumber = t1.FEmpCode
LEFT join t_Department tdp on tdp.FItemID = tem.FDepartmentID 
LEFT join t_Supplier tsup on tsup.FItemID = t1.FSupplyID where 2=2 {$timeStr} {$fgxnameStr} {$fbillnoStr} {$jtnumberStr} {$fzynameStr} {$fhelpcodeStr} {$wlfnumberStr} ";
		
		$total = SqlServerUtil::exec($this->SqlServer, $sqlcount,2);
		
		$this->response['total'] = $total ? $total['count']:0;
		$this->response['size'] = 1;
		$last_page =0;
		if($total && count($total)>0){
			$last_page = ceil($total['count']/$limit);
			$this->response['size'] = $limit;
		}
		$this->response['result'] = $res;
		$this->response['last_page'] =$last_page;
		return response()->json($this->response);
		showMsg(200,'成功', $res);
	}
	
	/**
	* 聚一科技 ^_^
	* ERP-职员信息 /api/erpZhiyuan
	* @date: 2020年9月9日
	* @author: lq
	* @version:App V2.0
	*/
	public function erpZhiyuan(Request $request){
		$page= $request ->get('page');
		if(!isset($page)) $page =1;
		$limit= $request ->get('limit');
		if(!isset($limit)) $limit =20;
		$pages = ($page-1)* $limit;
		
		$wlfnumberStr='';
		if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
			$keyword = $request->keyword;
			$wlfnumberStr=" and (t1.fname like '%{$keyword}%' or t1.fnumber like '%{$keyword}%'  )";
		}
		//部门
		$fdeptnameStr='';
		if ($request->has('fdeptname') and $request->fdeptname != '' and !empty($request->fdeptname)) {
			$fdeptname = $request->fdeptname;
			$fdeptnameStr=" and  sub4.fname = '{$fdeptname}' ";
		}
		
		//公司名称
		$fcompanyStr='';
		if ($request->has('fcompany') and $request->fcompany != '' and !empty($request->fcompany)) {
			$fcompany = $request->fcompany;
			$fcompanyStr=" and  t1.fcompany like '%{$fcompany}%' ";
		}
		
		//入场时间
		$timeStr ='';
		$patten = "/^[1-9]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/";
		if ($request->has('start_time') and $request->start_time != '' and $request->start_time != 'null') {
			if($request->has('end_time') and $request->end_time != '' and $request->end_time != 'null'){
				if(preg_match($patten,$request->end_time))
				{
					$etime = $request->end_time;
				}else{
					showMsg(400,'结束时间格式不正确');
				}
			}
			if(preg_match($patten,$request->start_time))
			{
				$stime = $request->start_time;
				$timeStr="and t1.FHireDate >='{$stime}' and t1.FHireDate<='{$etime} 23:59:59' "	;
			}else{
				showMsg(400,'时间格式不正确');
			}
		}
		
		
		$fdeletedStr='';
		if($request->fdeleted == 1){
			$fdeletedStr=" and t1.fdeleted = 0";
		}elseif($request->fdeleted == 2){
			$fdeletedStr=" and t1.fdeleted = 1";
		}elseif($request->fdeleted == 3){
			$fdeletedStr=" and t1.fdeleted = 2";
		}elseif($request->fdeleted == 4){
			$fdeletedStr=" and t1.fdeleted = 3";
		}elseif($request->fdeleted ==5){
			$fdeletedStr=" and t1.fdeleted = 4";
		}elseif($request->fdeleted == 6){
			$fdeletedStr=" and t1.fdeleted = 5";
		}elseif($request->fdeleted == 7){
			$fdeletedStr=" and t1.fdeleted = 6";
		}
		
		
		//FCreditAmount  --工龄奖 ,Femail -- 工龄
		/* ,tdp.fname as FDeptName
		,tsub1.fname as FGenderName
		,tsub2.fname as FDegreeName
		,tsub3.fname as FDutyName */
		$sql="select top $limit * from (
		SELECT
		row_number() over(order by t1.fnumber desc) as rownumber,
		t1.FItemID,t1.Fnumber,t1.Fname
		from gz_Emp t1
		LEFT JOIN gz_SubMessage sub1 ON sub1.FInterID = t1.FDegree 
		AND sub1.FTypeID = 23
		LEFT JOIN gz_SubMessage sub2 ON sub2.FInterID = t1.fduty 
		AND sub2.FTypeID = 29
		LEFT JOIN gz_SubMessage sub3 ON sub3.FInterID = t1.fgender 
		AND sub3.FTypeID = 102
		LEFT JOIN gz_SubMessage sub4 ON sub4.FInterID = t1.fdepid 
		AND sub4.FTypeID = 30
		LEFT JOIN gz_SubMessage sub5 ON sub5.FInterID = t1.FDeleted 
		AND sub5.FTypeID = 200 
		where 1=1 and t1.FItemID>0 and sub5.Fname in ('在职') {$wlfnumberStr} {$fdeletedStr} {$fdeptnameStr} {$fcompanyStr} {$timeStr}) temp_row  where rownumber>(($page-1)*$limit)"; 
		$res = SqlServerUtil::execTosqlOK($this->SqlServer, strtolower($sql));
		if($res && count($res)>0){
			$res  = arraykeyToLower($res);
		}	
		$sqlcount ="SELECT count(*) count
		from t_Emp t1
		left join t_department tdp on tdp.fitemid=t1.FDepartmentID
		left join t_submessage tsub1 on tsub1.finterid=t1.Fgender
		left join t_submessage tsub2 on tsub2.finterid=t1.Fdegree
		left join t_submessage tsub3 on tsub3.finterid=t1.Fduty
		where 1=1 and t1.FItemID>0 and t1.fdeleted =0  {$wlfnumberStr} {$fdeletedStr} {$fdeptnameStr} {$fcompanyStr} {$timeStr}";
		
		$total = SqlServerUtil::exec($this->SqlServer, $sqlcount,2);
		$this->response['total'] = $total ? $total['count']:0;
		$this->response['size'] = 1;
		$last_page =0;
		if($total && count($total)>0){
			$last_page = ceil($total['count']/$limit);
			$this->response['size'] = $limit;
		}
		$this->response['result'] = $res;
		$this->response['last_page'] =$last_page;
		return response()->json($this->response);
		showMsg(200,'成功', $res);
		
	}
	/**
	* 聚一科技 ^_^
	* APP登录用户
	* @date: 2020年10月31日
	* @author: lq
	* @version:App V2.0
	*/
	public function appUser(Request $request){
		$sql="select top 10000 id ,username from gz_admin where username !='manager' and status =1 order by id desc";
		$res = SqlServerUtil::exec($this->SqlServer, $sql);
		showMsg(0,'成功',$res);
	}
	
	/**
	* 聚一科技 ^_^
	* 职员信息 /api/zyInsert
	* @date: 2020年10月21日
	* @author: lq
	* @version:App V2.0
	*/
	public function zhiyuanInsert(Request $request){
		//默认0001
		//获取职员名称
		$zhiyuanname = $request->get('fname');
		if(empty($zhiyuanname)){
			showMsg(400,'职员名称不能为空');
		}
		$fnumber = $request->get('fnumber'); //工号
		if(empty($fnumber)){
			showMsg(400,'工号不能为空');
		}
		
		$param = $request->all();
		$param = _unsetNull($param);
		$fid = $request->get('fitemid');
		//分管部门
		//FDeptName -------Fdepartment
		$Fdepartment= 0;
		$param['FDepartmentID'] =0;
		if($request->has('fdeptname') and $request->fdeptname != '' && !empty($request->fdeptname)){
			$FDeptNamestr=  $request->fdeptname ;
			$FDeptName = SqlServerUtil::execToSql($this->SqlServer,"SELECT FItemID,FName FROM t_department where Fname ='{$FDeptNamestr}'",2);
			if(empty($FDeptName)){
				showMsg(400,'分管部门不正确！');
			}
			$Fdepartment = $FDeptName['FItemID'];
			$param['FDepartmentID'] = $Fdepartment;
		}
		
		
		//学位  select * from t_submessage where FTypeID= 23  ---  fdegreename
		$fdegree= 0;
		$param['FDegree'] =0;
		if($request->has('fdegreename') and $request->fdegreename != '' && !empty($request->fdegreename)){
			$fdegreenamestr=  $request->fdegreename ;
			$fdegreeData = SqlServerUtil::execToSql($this->SqlServer,"select FInterID from t_submessage where FTypeID= 23 and Fname ='{$fdegreenamestr}'",2);
			if(empty($fdegreeData)){
				showMsg(400,'学位不正确！');
			}
			$fdegree = $fdegreeData['FInterID'];
			$param['FDegree'] = $fdegree;
		}
		//FDutyName 职务     //select * from t_submessage where FTypeID= 29 --职务
		$fduty= 0;
		$param['FDuty'] =0;
		if($request->has('fdutyname') and $request->fdutyname != '' && !empty($request->fdutyname)){
			$fdutynamestr=  $request->fdutyname ;
			$fdutyData = SqlServerUtil::execToSql($this->SqlServer,"select FInterID from t_submessage where FTypeID= 29 and Fname ='{$fdutynamestr}'",2);
			if(empty($fdutyData)){
				showMsg(400,'职务不正确！');
			}
			$fduty = $fdutyData['FInterID'];
			$param['FDuty'] =$fduty;
		}
		
		//FGenderName 性别  //select * from t_submessage where FTypeID= 102   --性别
		$fgender= 0;
		$param['FGender'] =0;
		if($request->has('fgendername') and $request->fgendername != '' && !empty($request->fgendername)){
			$fgendernamestr=  $request->fgendername ;
			$fgenderData = SqlServerUtil::execToSql($this->SqlServer,"select FInterID from t_submessage where FTypeID= 102 and Fname ='{$fgendernamestr}'",2);
			if(empty($fgenderData)){
				showMsg(400,'性别不正确！');
			}
			
			$fgender = $fgenderData['FInterID'];
			$param['FGender'] = $fgender;
		}
		
		//gegng
		// 启动事务
		if (sqlsrv_begin_transaction($this->SqlServer) === false) {
			die(print_r(sqlsrv_errors(), true));
		}
		//1--更新 fitemid
		
		//dd($request->fitemid,999999);
		if($request->has('fitemid') and $request->fitemid != '' && !empty($request->fitemid)){
			if(empty($request->fitemid)){
				showMsg(400,'工号不能为空');
			}
			unset($param['fitemid']);
			unset($param['db']);
			//unset($param['fname']);
			unset($param['fgendername']);
			unset($param['fdutyname']);
			unset($param['fdegreename']);
			unset($param['fdeptname']);
			//$u1 = SqlServerUtil::exeupdateTosql($this->SqlServer, "t_item", $param,['fitemid'=>$fid]);
			$u2 = SqlServerUtil::exeupdateTosql($this->SqlServer, "t_emp", $param,['fitemid'=>$fid]);
			if($u2){
				sqlsrv_commit($this->SqlServer);
				showMsg(200,'成功');
			}else {
				sqlsrv_rollback($this->SqlServer);
				showMsg(400,'修改失败');
			}
			//dd(2222  );
			
		}else{
			//判断职员
			$customertemp=  $zhiyuanname ;
			/* $cust = SqlServerUtil::execToSql($this->SqlServer, "select FItemID,FName,FNumber from t_item where fdetail=1 and fitemclassid=3 and fparentid= 0 and FName= '{$customertemp}'",2);
			if($cust){
				showMsg(400,'职员名称重复');
			} */
		}
		
		$ghcust = SqlServerUtil::execToSql($this->SqlServer, "select FItemID,FName,FNumber from t_item where fdetail=1 and fitemclassid=3 and fparentid= 0 and FNumber= '{$fnumber}'",2);
		if($ghcust){
			showMsg(400,'工号 重复');
		}
		
		//工号
// 		$fnumber=0001;
// 		$ghsql= "select max(fnumber) fnumber  from t_item where 1=1 and len(fnumber) >= 4 and fdetail=1 and fitemclassid=3 and fparentid= 0";
// 		$ghdata = SqlServerUtil::execToSql($this->SqlServer,$ghsql,2);
// 		if($ghdata){
// 			$fnumber = $ghdata['fnumber']+1;
// 			$fnumber = strpadTostring($fnumber);
// 		}
		$t_itemData=[
				'FItemClassID'=>3,
				//'FExternID'=>-1,
				'FNumber'=>$fnumber,
				'FParentID'=>0,
				'FLevel'=>1,
				'FDetail'=>1,
				'FName'=>$customertemp,
				//'FUnUsed'=>0,
				//'FBrNo'=>0,
				'FFullNumber'=>$fnumber,
				//'FDiff'=>0,
				//'FDeleted'=>0,
				'FShortNumber'=>$fnumber,
				'FFullName'=>$customertemp,
				//'FGRCommonID'=>-1,
				//'FSystemType'=>1,
				//'FUseSign'=>0,
				//'FChkUserID'=>0,
				//'FGrControl'=>-1,
				'FBrNo'=>1,
		];
		
		try {
			$res=  SqlServerUtil::sqlsrvCreate($this->SqlServer,'t_item',$t_itemData);
			$FItemID = 0;
			$t_optData=[
					'FItemID'=>-99,  //$FItemID
					'FDuty'=>$fduty,
					'FDegree'=>$fdegree,
					'FGender'=>$fgender,
					//'FItemDepID'=>$Fdepartment,
					//'FBrNO'=>1,
					'FEmpGroupID'=>0,
					
					'FName'=>$customertemp,
					'FNumber'=>$fnumber,
					//'FParentID'=>0,
					'FShortNumber'=>$fnumber,
					'FDeleted'=>isset($param['fdeleted'])?$param['fdeleted']:0,
					'FDepartmentID'=>$Fdepartment,
					//'FEmpGroup'=>0,
					//'FEmpGL'=>'',
					//'FSCEmpCode'=>'',
					
					'FID'=>$param['fid'], //身份证
					'GongZi'=>isset($param['gongzi'])?$param['gongzi']:0, //基本工资
					'FLeaveDate'=>$param['fleavedate'], //辞职日期
					'FHireDate'=>$param['fhiredate'], //入厂时间
					'FBankAccount'=>$param['fbankaccount'], //浦发银行卡号
					'FAddress'=>isset($param['faddress'])?$param['faddress']:'', //地址
					'FPhone'=>isset($param['fphone'])?$param['fphone']:'', //电话
					
					'FBirthday'=>isset($param['fbirthday'])?$param['fbirthday']:'', //出生日期
					'FNote'=>isset($param['fnote'])?$param['fnote']:'', //备注
					'FCompany'=>isset($param['fcompany'])?$param['fcompany']:'', //公司名称
					'FHelpCode'=>isset($param['fhelpcode'])?$param['fhelpcode']:'', //户名
					'FISZZ'=>isset($param['fiszz'])?$param['fiszz']:'', //是否转正
					
					'FGWName'=>isset($param['fgwname'])?$param['fgwname']:'', //工位名称
					
					'FCreditAmount'=>isset($param['fcreditamount'])?Floatval($param['fcreditamount']):0, //工龄奖
					'Femail'=>isset($param['femail'])?Floatval($param['femail']):0, //工龄
					'fjxgz'=>isset($param['fjxgz'])?Floatval($param['fjxgz']):0, //绩效工资
					
					'FSCEmpCode'=>isset($param['fscempcode'])?$param['fscempcode']:'', //zu名称
					
					
			];
			$update = true;
			$res_opt =SqlServerUtil::sqlsrvCreate($this->SqlServer,'t_emp',$t_optData);
			if($res && $res_opt && $update ){
				sqlsrv_commit($this->SqlServer);
				$update  = SqlServerUtil::sqlexec($this->SqlServer, "update org set org.FItemID =t.FItemID from t_emp org INNER JOIN t_Item t on t.FNumber = org.FNumber where t.fdetail=1 and t.fitemclassid=3 and t.fparentid= 0 and t.FNumber ='{$fnumber}' ");
					
				showMsg(200,'成功');
			}else {
				sqlsrv_rollback($this->SqlServer);
				showMsg(400,'添加职员名称失败');
			}
		} catch (Exception $e) {
			// 数据回滚, 当try中的语句抛出异常。
			sqlsrv_rollback($this->SqlServer);
			showMsg(400,'添加职员名称失败1');
		}
	}
	
	public function zhiyuanDel(Request $request)
	{
		$FItemID = $request ->get('fitemid');
		if(empty($FItemID)){
			showMsg(400,'传参错误');
		}
		// 启动事务
		if (sqlsrv_begin_transaction($this->SqlServer) === false) {
			die(print_r(sqlsrv_errors(), true));
		}
		$qkid = sqlsrv_query($this->SqlServer,"DELETE t_emp WHERE FItemID in ({$FItemID}) ");
		$qkid2 = sqlsrv_query($this->SqlServer,"DELETE t_item WHERE FItemID in ({$FItemID}) ");
		if($qkid && $qkid2){
			sqlsrv_commit($this->SqlServer);
			showMsg(200,'删除成功');
		}else{
			sqlsrv_rollback($this->SqlServer);
			showMsg(400,'删除失败');
		}
	}
	
	/**
	* 聚一科技 ^_^
	* 加载
	* @date: 2020年9月17日
	* @author: lq
	* @version:App V2.0
	*/
	public function jiazai(Request $request){
		
			
		
		
	}
	
	/**
	* 聚一科技 ^_^
	* 计算 /api/jisuan
	* @date: 2020年9月17日
	* @author: lq
	* @version:App V2.0
	*/
	public function jisuan(Request $request){
		set_time_limit(0);
		$qijian = $request->get('qjValue');
		$fcompanyStr =  "";  //SQ  ,  
		//公司
		if ($request->has('fcompany') and $request->fcompany != '' and !empty($request->fcompany)) {
			$fcompanyStr=" and (t1.fcompany like '%{$request->fcompany}%' )";
		}
		
		$nameStr = '';
		//员工名称 
		if ($request->has('fname') and $request->fname != '' and !empty($request->fname)) {
			$nameStr=" and (t1.FName like '%{$request->fname}%' )";
		}
		
		$fdepStr ='';
		if ($request->has('fdeptname') and $request->fdeptname != '' and !empty($request->fdeptname)) {
			$fdeptname =  $request->fdeptname ;
			$fdepStr=" and (sub4.fname = '{$fdeptname}' )";
		}
		
		
		
		$limit =10000;
		$page=1;
		$kqData =[];
		$limit=10000;
		list($Year, $Month ) = explode('-',$qijian);
		$Month = intVal($Month);
		
		if($Month == 1){
			$year1= $Year-1;
			$syYear = " and v2.FYear = '{$year1}' ";
			$syMonth= " and v2.FPeriod = 12 " ;
		}else{
			$mon1= $Month-1;
			$syYear = " and v2.FYear = '{$Year}' ";
			$syMonth= " and v2.FPeriod = {$mon1} " ;
		}
		//判断该用户是否有考勤
		$sql ="SELECT  row_number ( ) OVER ( ORDER BY t1.FNumber ) AS rownumber,
			$Year FYear,
			$Month FPeriod,
			t1.FItemID,
			t1.FName,
			t1.FNumber,
			t1.fsfz AS FIdentityNo,
			t1.FHireDate,
			t1.FLeaveDate,
			t1.FAddress AS FpufaBank,
			t1.FBankAccount,
			t1.Fnote AS FBMnote,

			u4.FZWDJ ,
			u4.FFFFS,
			isnull( gzkq.FYCQ, 0 ) AS FYCQ,
			isnull( gzkq.FSCQ, 0 ) AS FSCQ,
			isnull( gzkq.FPJ, 0 ) AS FPJ,
			isnull( gzkq.FLJ, 0 ) AS FZLJ,
			isnull( gzkq.FFDJH, 0 ) AS FJBFD,
			isnull( u4.FYXJ, 0 ) AS FYXJ,
			isnull( u4.FZCJEW, 0 ) AS FZCJEW,
			isnull( u4.FPYJ, 0 ) AS FPYJ,
			isnull( u4.FPJEW, 0 ) AS FPJEW,
			isnull( u4.FLYJ, 0 ) AS FZLYJ,
			isnull( u4.FLJEW, 0 ) AS FZLJEW,
			isnull( u4.FMJEW, 0 ) AS FZMJ,
			isnull( u4.FPSJ, 0 ) AS FPSJ,
			isnull( u4.FPSEWJBBQQ, 0 ) AS FPSEWJBBQQ,
			isnull( u4.FZMEWJBBQQ, 0 ) AS FZMEWJBBQQ,

			isnull( gzkq.FHSBT, 0 ) AS FHSBZ,
			isnull( gzkq.FDHFBT, 0 ) AS FDHFBZ,
			isnull( gzkq.FSBKKF, 0 ) AS FSBKK,
			isnull( gzkq.FGSKKF, 0 ) AS FLYK,
			isnull( gzkq.FQTKKF, 0 ) AS FQTKK,
			isnull( gzkq.FKQBT, 0 ) AS FYXBZ,
			isnull( gzkq.FKSDF, 0 ) AS FKSDF,
 

case when gzkq.FYCQ - gzkq.FSCQ >0 then  -abs(round((u4.Fjbgz + ISNULL(u4.FZFBT, 0)+ISNULL(u4.FGWBT, 0) )*(gzkq.FYCQ - gzkq.FSCQ)/8/(gzkq.FYCQ/8) ,2))
else 0 end  as  FQQKK,
			 
			isnull( u4.FHJ, 0 ) AS FHJ,
			isnull( u4.FGWBT, 0 ) AS FGWBZ,
			isnull( u4.FCJ, 0 ) AS FCJ,
			isnull( u4.FTCBT, 0 ) AS FTCBZ,
			isnull( u4.FJLBT, 0 ) AS FJLBZ,
			isnull( u4.FNJ, 0 ) AS FNJ,
			isnull( u4.FQGJ, 0 ) AS FQGJ,
			isnull( u4.FZFGJ, 0 ) AS FZFGJ,
		    isnull( u4.FZFBT, 0 ) AS FZFBZ,
			isnull( u4.FGLGZ, 0 ) AS FGLGZ,
			
			isnull( u4.FFPK, 0 ) AS FFPK,
			isnull( u4.FKJK, 0 ) AS FKJK,		
			isnull( u4.FKK, 0 ) AS FKK,
			isnull( u4.FdwSB, 0 ) AS FdwSB,
			isnull( u4.Fjbgz, 0 ) AS FYFGZ,
			isnull( u4.Fjxgz, 0 ) AS FJXGZ,

			isnull( u4.FQQJ, 0 ) AS FQQJ,
			isnull( u4.Fjbgz, 0 ) AS FJBGZ,
			isnull( u4.Fjbgz, 0 ) AS FGZXJ,
			isnull( u4.Fjbgz, 0 ) AS FBZJBGZ,
			isnull( u4.Fjbgz, 0 ) AS FBZJXGZ,
			isnull( u4.FTBBZ, 0 ) AS FTBBZ,
			isnull( u4.FTXBZ, 0 ) AS FTXBZ,

			isnull(jj.FJJGZ, 0) AS FJJGZ,
			isnull(js.FJSGZ, 0) AS FJSGZ,

			sub4.fname AS FBM,
			sub1.fname AS FGenderName,
			sub2.fname AS FZW,
			sub3.fname AS FDegreeName,
			0 AS FStatus,'' AS FFuStatus

		FROM
			gz_Emp t1
			LEFT JOIN gz_SubMessage sub1 ON sub1.FInterID = t1.FDegree 
			AND sub1.FTypeID = 23
			LEFT JOIN gz_SubMessage sub2 ON sub2.FInterID = t1.fduty 
			AND sub2.FTypeID = 29
			LEFT JOIN gz_SubMessage sub3 ON sub3.FInterID = t1.fgender 
			AND sub3.FTypeID = 102
			LEFT JOIN gz_SubMessage sub4 ON sub4.FInterID = t1.fdepid 
			AND sub4.FTypeID = 30
			LEFT JOIN gz_SubMessage sub5 ON sub5.FInterID = t1.FDeleted 
			AND sub5.FTypeID = 200 
			LEFT JOIN gz_SubMessage sub6 ON sub6.FInterID = t1.FDeleted 
			AND sub6.FTypeID = 301 
			
			LEFT JOIN (
				SELECT
					SUM (isnull(FPlanAmount, 0)) FJJGZ,
					FEmpCode
				FROM
					gz_gzzyjj
				WHERE
					Fstatus =1 and
					FPeriod = '{$Month}'
				AND FYear ='{$Year}'
				GROUP BY
					FEmpCode
			) AS jj ON jj.FEmpCode = t1.FNumber
			LEFT JOIN (
				SELECT
					SUM (isnull(FjsAmount, 0)) FJSGZ,
					FItemID
				FROM
					gz_gzzyjs
				WHERE
					FPeriod = '{$Month}'
				AND FYear = '{$Year}' and  FStatus =1
				GROUP BY
					FItemID
			) js ON js.fitemid = t1.FItemID
					
			LEFT JOIN gz_gzzykq u4 ON u4.fitemid = t1.fitemid 
			AND u4.FYear = '{$Year}' AND u4.FPeriod = '{$Month}'  AND u4.FStatus = 1
			LEFT JOIN gz_Grade dj ON u4.FZWDJ = dj.FName  
			left join gz_gzkaoqin gzkq on gzkq.fitemid = t1.fitemid  AND gzkq.FYear = '{$Year}' AND gzkq.FPeriod = '{$Month}'  AND gzkq.FStatus = 1
		WHERE
			1 = 1 
			AND t1.FItemID > 0 
			AND t1.FDeleted in (select finterid from gz_SubMessage where fname ='在职')  {$nameStr} {$fcompanyStr} {$fdepStr} and t1.FItemID not in (
			select FItemID from gz_gzlb where FYear= '{$Year}' and FPeriod = '{$Month}' and FStatus =1) and gzkq.FYCQ !=0  ";
// 			echo $sql;die;
			$kqData = SqlServerUtil::execToSql($this->SqlServer, strtolower($sql));
			$tempKq =[];
// 			dd($kqData);
			// 考虑提成问题 
			//AND gzkq.FSCQ !=0 and isnull(u4.Fjbgz, 0)>0
			
			//过滤
			if($kqData){
				foreach ($kqData as $kk =>$vv)
				{
// 					&& $vv['fscq'] !=0
					if($vv['fycq'] + $vv['fyxj'] - $vv['fscq'] >=0 ){
						$tempKq[]=$vv;
					}
				}
				
			}else{
				$this->response['result'] = [];
				$this->response['total'] = 0;
				$this->response['size'] = 1;
				$this->response['last_page'] =1 ;
				$this->response['Message'] = "职员记录为空,或当月出勤记录为空!!!";
				return response()->json($this->response);
				showMsg(400,"职员记录为空,或当月出勤记录为空!!!");
			}
		 
			//参数控制  -- fworktime == 工作制  ， fisusergrade == 使用员工等级 ， fxiaoshishu == 按多少天计算
			$getSystemProfile = $this->getSystemProfile();
			$fworktime = $getSystemProfile['fworktime'];//1-周一到周五8小时，2-周一到周五及周六8小时
			$fisusergrade = $getSystemProfile['fisusergrade'];  //0:不使用，非空 1：使用
			$fxiaoshishu = $getSystemProfile['fxiaoshishu']; //工资每月按多少天数计算 21
			$fqqjset = $getSystemProfile['fqqjset']; //全勤奖规则计算
			$fqqjbz = $getSystemProfile['fqqjbz']; //全勤奖是否添加到补助项，1-是，0-否
			$FSetCusomer = $getSystemProfile['fsetcusomer']; //指定客户
			$FSetFjxvalue = $getSystemProfile['fsetfjxvalue']; //减项 默认为正 
			
			if($tempKq){
				if($FSetCusomer ==1){
					foreach ($tempKq as $kk =>&$vv)
					{
						//基本工资  -(基本工资/26)*(应出勤 - 实际出勤)
						//按小时计算
						$vv['fsjjbgz'] = 0;
						
						if($vv['fycq']+ $vv['fyxj'] - $vv['fscq'] >=0 && $vv['fscq'] >0){
							// 实际工资
							$vv['fsjjbgz'] =  round($vv['fyfgz'] - ($vv['fyfgz']*($vv['fycq']+ $vv['fyxj'] - $vv['fscq'])/($vv['fycq']+ $vv['fyxj']) ),2) ;
						}
						
						if($vv['fycq']  == 0 ||  $vv['fscq'] == 0 || ($vv['fycq'] + $vv['fyxj'] -  $vv['fscq']) <0){
							$vv['fsjjbgz'] = 0;
						}
					
						//补助合计  
						//补助合计 =伙食补助fhsbz+高温补助fgwbz+夜宵补助fyxbz+产假陪护假补助fcj+电话费补助fdhfbz+业务提成 ftcbz+奖励fjlbz+婚假补贴fhj+春节放假补贴 fnj + 计件 ，计时
						// +勤工奖fqgj
						// dd($vv['fhsbz']  ,$vv['fgwbz'],$vv['fyxbz'] ,$vv['fcj'], $vv['fdhfbz'],$vv['ftcbz'],$vv['fjlbz'] , $vv['fhj'] , $vv['fnj'], $vv['fqgj'] , $vv['fqqj'],  $vv['fjjgz'],$vv['fjsgz'] );
						$vv['fbzhj'] =  $vv['fhsbz']  +$vv['fgwbz']+$vv['fyxbz'] +$vv['fcj']+ $vv['fdhfbz']+$vv['ftcbz']+$vv['fjlbz'] + $vv['fhj'] + $vv['fnj']+ $vv['fqgj'] + $vv['fqqj']+  $vv['fjjgz']+$vv['fjsgz'] ;

// 						dd($vv['fhsbz']  ,$vv['fgwbz'],$vv['fyxbz'] ,$vv['fcj'],$vv['fdhfbz'],$vv['ftcbz'],$vv['fjlbz'] , $vv['fhj'] , $vv['fnj'], $vv['fqgj'] , $vv['fqqj'],  $vv['fjjgz'],$vv['fjsgz']);
						//应发合计   FZFBZ --加班费
						$vv['fyfhj'] = $vv['fyfgz'] + $vv['fzfbz'] + $vv['fbzhj'];
// 						dd($vv['fyfhj'],$vv['fsjjbgz'] , $vv['fzfbz'] , $vv['fbzhj']);
						//扣款合计 = 养老保险fylbx + 医保fyb + 公积金fzfgj + 缺勤扣款fqqkk + 代扣税fdks + 餐费fcf + 扣工衣fkgy +
						//罚赔款ffpk现金暂扣款 + 扣借款fkjk请假扣款 + fsdf扣水电费fksdf + 旅游款flyk + 其他扣款fqtkk + 迟到扣款fkk + 请假扣款 fqjkk
						
						//扣款合计 =  社保费fsbkk + 住宿费flyk + 考勤扣款fqqkk+ 公告扣款fkjk + 补签卡扣款ffpk+ 水电费及其他 fksdf
						//+公积金 fzfgj + 其他扣款fqtkk
						$vv['fkkhj'] = $vv['fdwsb']+ $vv['fsbkk']+$vv['flyk']+ $vv['fqqkk'] + $vv['fkjk']+  $vv['ffpk'] +$vv['fksdf'] +  $vv['fzfgj'] +$vv['fqtkk']  ;

						//实发合计 = 应发合计  -扣款合计
						if($FSetFjxvalue == 1){
							$vv['fsfhj'] = round($vv['fyfhj']  +  $vv['fkkhj'] ,2) ;
						}else{
							$vv['fsfhj'] = round($vv['fyfhj']  -  $vv['fkkhj'] ,2) ;
						}
				 
						// fsfhj ---实发合计 ,fyfhj -- 应发合计
// 						if($vv['fsfhj'] <= 0){
// 							unset($tempKq[$kk]);
// 							continue;
// 						}
					 
					}
				 
				}else{
					//当月上班小时数
					$xiaoshi = $fxiaoshishu * 8 ;
					foreach ($tempKq as $kk =>&$vv) 
					{
						//基本工资  -(基本工资/26)*(应出勤 - 实际出勤)
						//按小时计算  
						$vv['fsjjbgz'] = 0;
		 
						if($vv['fycq']+ $vv['fyxj']  -  $vv['fscq'] >=0 && $vv['fscq'] >0){
							// 实际工资 
							if($fworktime == 1){
								$vv['fsjjbgz'] =  round($vv['fyfgz'] - ($vv['fyfgz']*($vv['fycq']+ $vv['fyxj'] - $vv['fscq'])/($vv['fycq']+ $vv['fyxj']) ),2) ;
							}elseif($fworktime == 2){
								$vv['fsjjbgz'] =  round($vv['fjbgz'] - ($vv['fjbgz']*($vv['fycq']+ $vv['fyxj'] - $vv['fscq'])/($vv['fycq']+ $vv['fyxj']) ),2) ;
							}
						}
						
						if($vv['fycq']  == 0 ||  $vv['fscq'] == 0 || ($vv['fycq'] + $vv['fyxj'] -  $vv['fscq']) <0){
							$vv['fsjjbgz'] = 0;
						}
						//正班缺勤时 = 应上班+ 有薪假 - 实出勤-额外正常假
						//round()对浮点数进行四舍五入
						$vv['fzcqq']  = $vv['fycq'] + $vv['fyxj'] - $vv['fscq'] - $vv['fzcjew'];
						//满勤奖励 200
						$vv['fqqj'] = getjsqqj($fqqjset,$vv['fzcqq']);
	// 					// 综合工资  fyfgz
						$vv['fgzxj'] = $vv['fyfgz'];
						//补助合计
						//全勤奖是否添加到补助项  1-是，0-否
						if(empty($fqqjbz)){
							//补助合计 =伙食补助fhsbz+高温补助fgwbz+夜宵补助fyxbz+产假陪护假补助fcj+电话费补助fdhfbz+业务提成 ftcbz+奖励fjlbz+婚假补贴fhj+春节放假补贴 fnj + 计件 ，计时
							// +勤工奖fqgj
							$vv['fbzhj'] =  $vv['fhsbz']  +$vv['fgwbz']+$vv['fyxbz'] +$vv['fcj']+ $vv['fdhfbz']+$vv['ftcbz']+$vv['fjlbz']+ $vv['fhj'] + $vv['fnj']+ $vv['fqgj'] +  $vv['fjjgz']+$vv['fjsgz'] ;
							
						}else{
							$vv['fbzhj'] =  $vv['fhsbz']  +$vv['fgwbz']+$vv['fyxbz'] +$vv['fcj']+ $vv['fdhfbz']+$vv['ftcbz']+$vv['fjlbz']+ $vv['fhj'] + $vv['fnj']+ $vv['fqgj'] + $vv['fqqj']+  $vv['fjjgz']+$vv['fjsgz'] ;
						}
						//扣款合计 = 养老保险fylbx + 医保fyb + 公积金fzfgj + 缺勤扣款fqqkk + 代扣税fdks + 餐费fcf + 扣工衣fkgy +
						//罚赔款ffpk现金暂扣款 + 扣借款fkjk请假扣款 + fsdf扣水电费fksdf + 旅游款flyk + 其他扣款fqtkk + 迟到扣款fkk + 请假扣款 fqjkk
						//扣款合计 =  社保费fsbkk + 住宿费flyk + 考勤扣款fqqkk+ 公告扣款fkjk + 补签卡扣款ffpk+ 水电费及其他 fksdf
						//+公积金 fzfgj + 其他扣款fqtkk
						$vv['fkkhj'] =  round( $vv['fdwsb']+ $vv['fsbkk']+$vv['flyk']+ $vv['fqqkk'] + $vv['fkjk']+  $vv['ffpk'] +$vv['fksdf'] +  $vv['fzfgj'] +$vv['fqtkk'],2) ;
						$vv['fgzcy'] = 0;
						$vv['fjbewxsf'] =0;
						$vv['fsjzwbt'] = 0 ;
						//1-周一到周五8小时， 2-周一到周五及周六8小时
						if($fworktime == 1){
							$vv['fzgs']  = $vv['fscq'] +  $vv['fzmj'] + $vv['fjbfd'];
							$vv['fyzgs']  = $vv['fycq']  + $vv['fyxj'] ;
							//管理津贴
							$vv['fbzhj'] += $vv['fglgz'];
							//fyfgz
							//平时加班费 = 基本工资/168* (普通加班 + 普通额外加班)*1.5
							$vv['fpsjf']  = round($vv['fyfgz']/($xiaoshi)*($vv['fpj'] + $vv['fpjew'])*1.5 ,2);
							//周六加班费 = 基本工资/168* (周六加班 + 周六额外加班)*2
							$vv['fzljf']  = round($vv['fyfgz']/($xiaoshi)*($vv['fzlj'] + $vv['fzljew'])*2 ,2);
							//法定假加班费 = 基本工资/168* (法定加班)*3
							$vv['fjbfdf']  = round($vv['fyfgz']/($xiaoshi) * $vv['fjbfd']*3  ,2);
							
							//加班费用  -- 加班小时数
							$vv['fjbewxsf'] = $vv['fjbps'];
							$vv['fzmjf'] = round($vv['fyfgz']/$xiaoshi * $vv['fzmj'] ,2);
							
							$vv['fyfhj'] = $vv['fsjjbgz'] +$vv['fpsjf']+$vv['fzljf']+ $vv['fjbfdf'] +$vv['fzmjf'] + $vv['fbzhj'] ;
							
							
						}elseif ($fworktime == 2){
							//实际上班总工时 fzgs = fscq正常实际工时+ fpj平时实际加班时 + fzlj周六加班   + fzmj加班小时数 + fjbfd法定加班小时数 
							$vv['fzgs']  = $vv['fscq']+ $vv['fpj']+ $vv['fzlj']+ $vv['fzmj'] + $vv['fjbfd'];
							//应上班工时 = 应上班工时+ fpyj平时应加班时  + fzlj周六应普通加班
							$vv['fyzgs']  = $vv['fycq']  + $vv['fyxj'] + $vv['fpyj'] + $vv['fzlyj'];
							
							//平时加班费 = 基本工资/168* (普通加班 + 普通额外加班)*1.5
							$vv['fpsjf']  = round($vv['fjbgz']/($xiaoshi)*($vv['fpj'] + $vv['fpjew'])*1.5 ,2);
							//周六加班费 = 基本工资/168* (周六加班 + 周六额外加班)*2
							$vv['fzljf']  = round($vv['fjbgz']/($xiaoshi)*($vv['fzlj'] + $vv['fzljew'])*2 ,2);
							//法定假加班费 = 基本工资/168* (法定加班)*3
							$vv['fjbfdf']  = round($vv['fjbgz']/($xiaoshi) * $vv['fjbfd']*3  ,2);
							
							//加班费用  -- 加班小时数
							$vv['fjbewxsf'] = $vv['fjbps'];
							$vv['fzmjf'] = $vv['fjbps'] * $vv['fzmj'] ;
							
							
							$vv['fsjzwbt']  = round($vv['ftbbz']/($vv['fycq']+$vv['fyxj']+ $vv['fzlyj']+$vv['fpyj'] ) * ($vv['fscq']+ $vv['fzlj']+ $vv['fpj']) ,2 );
							
							$vv['fyfhj1'] = round($vv['fsjjbgz']+$vv['fqqj']+$vv['fpsjf'] +$vv['fzljf'] +$vv['fzmjf']
									+$vv['fsjzwbt']	+$vv['fglgz']+$vv['ftxbz']  +$vv['fzfbz']  +$vv['fbzhj']   ,2) ;
							
							//工时
							if($vv['fzgs'] - $vv['fyzgs']<0 ){
								//应发工资  = 竞业限制补偿金fzfbz ，技术津贴ftxbz ，职务津贴ftbbz ，基本工资fjbgz，全勤奖	fqqj
								//应发工资  = 竞业限制补偿金fzfbz ，技术津贴ftxbz ，职务津贴ftbbz ，基本工资fjbgz，全勤奖	fqqj
								$vv['fyfhj'] =  round(($vv['fgzxj']/$vv['fyzgs'])*$vv['fzgs'],2) + $vv['fbzhj'] ;
								$vv['fyfhj1'] = round($vv['fsjjbgz']+$vv['fqqj']+$vv['fpsjf'] +$vv['fzljf']+$vv['fzmjf']
										+$vv['fsjzwbt']	+$vv['fglgz']+$vv['ftxbz']  +$vv['fzfbz']  +$vv['fbzhj']   ,2) ;
							}else{
								$vv['fsjzwbt'] = $vv['ftbbz'];
								//dd($vv['fgzxj'],$vv['fjbps']*($vv['fzgs'] - $vv['fyzgs']) ,$vv['fbzhj'] );
								$vv['fyfhj'] = $vv['fgzxj'] + $vv['fjbps']*($vv['fzgs'] - $vv['fyzgs']) + $vv['fbzhj'] ;
							}
							$vv['fgzcy'] = $vv['fyfhj1'] - $vv['fyfhj'];  //工资差异
							
						}
						
						//实发合计 = 应发合计  -扣款合计
						$vv['fsfhj'] = round($vv['fyfhj']  -  $vv['fkkhj'] ,2) ;
						
						$vv['fzhsfhj'] = 0; //
						$vv['fsjgz'] = 0; //实际工资
						$vv['fyfhjldf'] = 0;//劳动法工资
						$vv['fldfgz'] = $vv['fyfhjldf'] ; //劳动法工资
						$vv['fsjtxbz'] = 0;  //实际技术津贴 
						 
						if($vv['fyfhj'] == 0){
							unset($tempKq[$kk]);
							continue;
						}
						 
					}
					
				}
			}
			 
// 			dd($tempKq);
			if($tempKq){
				$tempKq = array_values($tempKq);
			}
		$this->response['result'] = $tempKq;
		$this->response['total'] = count($tempKq)?count($tempKq):0;
		$this->response['size'] = 1;
		$last_page =1;
		
		if(count($tempKq)>0){
			$last_page = ceil(count($tempKq)/$limit);
			$this->response['size'] = $limit;
		}
		$this->response['last_page'] =$last_page;
		return response()->json($this->response);
		
	}
	
	/**
	 * 保存/api/scgzSave
	 * @date: 2020年3月4日 上午8:56:24
	 * @author: yy
	 */
	public function scgzSave(Request $request)
	{
		$param = $request ->get('rows');
		if(empty($param)){
			showMsg(400,'保存数据不能为空');
		}
		$data=[];
		$arr=[];
		foreach ($param as $k =>$v)
		{
			$data[$k]= [
					'fyear'=>$v['fyear'],
					'fperiod'=>$v['fperiod'],
					'fitemid'=>$v['fitemid'],
					
					//'fdjgz'=>floatval($v['fsjjbgz']),//实际工资
					'frgz'=>0,
					'fkhxs'=>0,
					'fjbgz'=>floatval($v['fjbgz']),  // 基本工资
					'fsjjbgz'=>floatval($v['fsjjbgz']),  //实际工资 
					'fbzjxgz' =>floatval($v['fbzjxgz']),  //标准基本工资
					'fbzjbgz' =>floatval($v['fbzjbgz']),  //标准基本工资 
					'fjxgz'=>0, //fjxgz -- 绩效工资
					'fkhgz'=>0,  //工资提成
					
					'fqqj'=>floatval($v['fqqj']),  //全勤奖
					
					'fpsjf'=>isset($v['fpsjf'])?floatval($v['fpsjf']):0,  //平时加班费
					'fzljf'=>isset($v['fzljf'])?floatval($v['fzljf']):0,  //周六加班费
					'fjbfdf'=>isset($v['fjbfdf'])?floatval($v['fjbfdf']):0,  //法定节假日加班费
					'fzmjf'=>isset($v['fzmjf'])?floatval($v['fzmjf']):0,  //周六周日额外加班费
					'fpsewf'=>0,  //平时额外加班费
					
					'fgzxj'=>floatval($v['fgzxj']), //工资小计==综合工资
					
					'fccbz'=>0,//出车
					'ftbbz'=>floatval($v['ftbbz']), //职务津贴
					'fsjzwbt'=>isset($v['fsjzwbt'])?floatval($v['fsjzwbt']):0, //实际职务津贴
					'fglgz'=>floatval($v['fglgz']), //管理津贴
					'ftxbz'=>floatval($v['ftxbz']), //技术津贴
					'fsjtxbz'=>isset($v['fsjtxbz'])?floatval($v['fsjtxbz']):0, //实际技术津贴
					'fzfbz'=>floatval($v['fzfbz']), //竞业限制补偿金
				
					
					'fgwbz'=>floatval($v['fgwbz']), //高温补助 
					'fhsbz'=>floatval($v['fhsbz']), //夜补
					'fyxbz'=>floatval($v['fyxbz']), //夜宵补助
					'fcj'=>floatval($v['fcj']),  //产假陪护假补助
					'fdhfbz'=>floatval($v['fdhfbz']),  //电话费补助
					'ftcbz'=>floatval($v['ftcbz']),  //业务提成
					'fjlbz'=>floatval($v['fjlbz']),  //奖励
					'fhj'=>floatval($v['fhj']),  //婚假补贴
					'fnj'=>floatval($v['fnj']),  //春节放假补贴
					
					'fcybz'=>0,
					'frcjb'=>0,
					'fqgj'=>0,
					'fyfhj'=>floatval($v['fyfhj']), //应发合计
					'fylbx'=>0,
					'fyb'=>0,
					
					'fjsgz'=>0, //计税工资 删
					'fdks'=>0,
					'fcf'=>0,
					'fkgy'=>0,
					
					'fsbkk' =>floatval($v['fsbkk']),  //社保缴费  
					'fqqkk'=>floatval($v['fqqkk']), //考勤扣款
					'flyk'=>floatval($v['flyk']), //住宿费
					'ffpk'=>floatval($v['ffpk']), // 补签卡扣款
					'fkjk'=>floatval($v['fkjk']), //公告扣款
					'fksdf'=>floatval($v['fksdf']), //水电费扣款
					'fqtkk'=>floatval($v['fqtkk']), //其他扣款
					'fkkhj'=>floatval($v['fkkhj']), //扣款合计
					'fsfhj'=> floatval($v['fsfhj']), //实发合计
					
					'fycq'=>floatval($v['fycq']), //应出勤
					'fscq'=>floatval($v['fscq']), //实际出勤
					'fzcqq'=>isset($v['fzcqq'])?floatval($v['fzcqq']):0, //正常缺勤(时)
					'fjbps'=> isset($v['fjbewxsf'])?floatval($v['fjbewxsf']):0,//额外加班小时数费用
					
					'fldfgz'=> isset($v['fldfgz'])?floatval($v['fldfgz']):0, //劳动法工资
					'fsjgz'=> isset($v['fsjgz'])?floatval($v['fsjgz']):0, //实际工资
					'fgzcy'=> isset($v['fgzcy'])?floatval($v['fgzcy']):0, //工资差异
					
					'fzgs'=> isset($v['fzgs'])?floatval($v['fzgs']):0, //实际总工时
					'fyzgs'=> isset($v['fyzgs'])?floatval($v['fyzgs']):0, //应上班 总工时
					
					
					'fzfgj'=>floatval($v['fzfgj']),  //住房公积金
					'fzkblje'=>0, //逾期暂扣金额
					'fzhsfhj'=> 0, //最后实发工资
					'fyhksxje'=>0, //已回款销售金额
					
					'stje'=>0,//浮动工资
					'fkyfgz'=>0,  //扣已发工资
					
					'fkk'=>0,  //迟到扣款
					
					//'fremark'=>$v['fremark'],  //逾期备注计
					'fjsgz' =>floatval($v['fjsgz']),  //计时工资
					'fjjgz'=>floatval($v['fjjgz']), //计件工资
					
					'FSFKK' =>0,  //宿舍水费
					'FDFKK' =>0,  //宿舍电费
					
					//'FDX' =>($v['FDX']),  //定薪
					//'FtxTime' => $v['FtxTime'] ,  // 调薪时间
					//'FdwSB' =>floatval($v['FdwSB']),  //单位缴纳社保
					//'FFFFS' => $v['FFFFS'] ,  //是否现金发放
					
			];
		}
		//存在
		$FItemID = array_column($data, 'fitemid');
		$FItemIDs = implode(',',$FItemID);
		// 启动事务
		if (sqlsrv_begin_transaction($this->SqlServer) === false) {
			die(print_r(sqlsrv_errors(), true));
		}
		$delete = sqlsrv_query($this->SqlServer, "delete from gz_gzlb where FItemID in ($FItemIDs) and FYear  ='{$v['fyear']}' and FPeriod ='{$v['fperiod']}'");
		$qkid=SqlServerUtil::sqlsrvAllTosql($this->SqlServer,'gz_gzlb',$data);
		
		if($qkid && $delete){
			sqlsrv_commit($this->SqlServer);
			showMsg(200,'保存成功');
		}else{
			sqlsrv_rollback($this->SqlServer);
			showMsg(400,'保存失败');
		}
	}
	
	/**
	* gz/test
	* @date: 2023年2月6日 上午10:23:10
	* @author: juyi
	*/
	public function test(Request $request){
	   
		//专利费
		$ZlData = SqlServerUtil::execToSql($this->SqlServer, "select * from gz_Yzhuanlif " );
		//排放检测费
		$pfjjData = SqlServerUtil::execToSql($this->SqlServer, "select *  from gz_Ypfceshif " );
		
		//图纸费
		$tzData = SqlServerUtil::execToSql($this->SqlServer, "select * from gz_Ytuzhif " );
		// 5X35-B
		$fmodel = '6X62DF-S' ; 
		$fbrand = 'WINGD' ; 
		$zlValue = $this->getTZValueQR( $tzData, $fmodel , $fbrand    ) ;
		
		dd($zlValue ,$tzData , 1111) ; 
		
		
		
		
		
		
		
		
		$rr = '6x40-b' ;
		
		dd(in_array($rr,['AA','BB','6x40-b']));
		
		
		
		
		$insertRecords =[];
		$insertRecords = arraykeyToLowerTo($insertRecords);
		dd($insertRecords);
		$user=[['focde'=>111],['focde'=>22]];
		//$result = array_reduce($a1, 'array_merge', array());
		$result = [];
		array_map(function ($value) use (&$result) {
			$result = array_merge($result, array_values($value));
		}, $user);
		dd($result);
		
// 		$rr = isHPLPSCRONE($fcodeData=[]  );
// 		$ff = 'fsetfucai535value';
		$ff = ['fsetfucai535value',
				'fsetfucai550value',
				'fsetfucaibzw535value',
				'fsetfucaibzw550value'] ;
		
		dd($this->getSystemProfile( ));
		
		
		
		
		
		
		
		
		
		$rr ="C.   膨胀节";
		$rr1 ='';
		$count =0;
		$arr = str_split($rr);
		$limitStr = array(" ","\t","\n","\r","\f","\v");
		$rr1 =  str_replace($limitStr,"",$rr ,$count); 
// 		$rr2 =  str_replace(" ","",$rr1 );
// 		$rr3 =  str_replace($limitStr,"",$rr2 );
		
		var_dump( $rr  , $rr1  );
		// , preg_split('/(?<!^)(?!$)/u', $rr )
		dd($count ,$rr ,$arr , strlen($rr1));
		 
		

		$serverConfig = [ "UID" => 'sa', "PWD" => 'Sa123', "Database" => 'kehuOrder'];
		$sqlCon = sqlsrv_connect('120.25.123.204', $serverConfig);
		dd( $sqlCon , $serverConfig) ;
		$res = SqlServerUtil::exec1($this->SqlServer, "selec * from t_article" ) ;
		dd( $res ) ;
		
		
		echo substr("Hello world",1,8)."<br>";
 
		
		
		
		
		
	}
	
	/**
	* 聚一科技 ^_^
	* @date: 2020年9月17日
	* @author: lq
	* @version:App V2.0
	*/
	public function gxFname(Request $request)
	{
		$fhelpcodeStr='';
		if ($request->has('gxcode') and $request->gxcode != '' and !empty($request->gxcode)) {
			$fhelpcode = $request->gxcode;
			$fhelpcode =iconv('UTF-8', 'GBK', gxcode);
			$fhelpcodeStr=" and FNumber like '%{$fhelpcode}%'";
		}
		$fnameStr='';
		if ($request->has('gxname') and $request->gxname != '' and !empty($request->gxname)) {
			$fgxname = $request->gxname;
			$fgxname =iconv('UTF-8', 'GBK', $fgxname);
			$fnameStr=" and FName like '%{$fgxname}%'";
		}
		
		$sql ="SELECT FItemID,FName,FNumber,FModel,FHelpCode from gz_wuliao  where 1=1 and fdeleted=0  {$fhelpcodeStr} {$fnameStr} ";
		$res=SqlServerUtil::exec($this->SqlServer, strtolower($sql) );
		if($res){
			showMsg(200,'成功',$res);
		}else{
			return response()->json(Common::errorResponse(400,'操作失败'));
		}
	}
	
	public function  wgAdd(Request $request){
		$fbatchno = $request->get('fbatchno')?$request->get('fbatchno'):'';//完工批号
		$loginname = $request->get('fname');//登录名称
		$gxcode = $request->get('fitemidnumber')?$request->get('fitemidnumber'):'';//工序代码
		$gxname = $request->get('fitemidname')?$request->get('fitemidname'):'';//工序名称
		
		$fgongxu = $request->get('fgongxu')?$request->get('fgongxu'):'';//工序 
		
		$lpsl = $request->get('fqtylp')?$request->get('fqtylp'):0;
		$blpsl = $request->get('fqtyblp')?$request->get('fqtyblp'):0;
		$fentrytext1 = $request->get('fentrytext1')?$request->get('fentrytext1'):'';//机台号
		$ycremark = $request->get('ycremark')?$request->get('ycremark'):'';//异常备注
		$fnote = $request->get('fnote')?$request->get('fnote'):'';//异常备注
		
		$blpnr = $request->get('fqtyblpnr')?$request->get('fqtyblpnr'):'';
		//$userid = $request->get('fempcode')?$request->get('fempcode'):'';//职员编号
		$fwgcj = $request->get('fwgcj')?$request->get('fwgcj'):'';//完工车间
		$username = $request->get('fentrytext2')?$request->get('fentrytext2'):'';//名字 -- id
		$fcustitemname = $request->get('fcustitemname')?$request->get('fcustitemname'):'';//app登录名称
		
		$fyear = $request->get('fyear')?$request->get('fyear'):date('y',time());//年度
		$fperiod = $request->get('fperiod')?$request->get('fperiod'):getcurrenttime(7) ;//月
		$fplanprice = $request->get('fplanprice')?$request->get('fplanprice'):0 ;//月
		
		if(empty($loginname)){
			showmsg(400,'登录名称不能为空');
		}
		//判断
		if(empty($fbatchno)){
			showmsg(400,'批次号不能为空');
		}
		
		$wl = SqlServerUtil::exec($this->SqlServer,"select fplanprice,fname,fnumber from gz_wuliao where fnumber ='{$gxcode}'",2);
		if(empty($wl)){
			showMsg(400,'工序名称不存在');
		}
		
		//$wlprice = $wl['fplanprice']?floatVal($wl['fplanprice']):0;
		
		$wlprice = $fplanprice;
// 		if($userid){
// 			$zyname = SqlServerUtil::exec($this->SqlServer,"select fname from gz_emp where fnumber ='{$userid}'",2);
// 			$zhiyuanName =  isset($zyname['fname'])?$zyname['fname']:'';
// 		}
		// $username == 5589
		if($username){
			$zyname = SqlServerUtil::execToSql($this->SqlServer,"select fname,fnumber from gz_emp where fitemid ='{$username}'",2);
			$userid =  isset($zyname['fnumber'])?$zyname['fnumber']:'';
			$zhiyuanname = isset($zyname['fname'])?$zyname['fname']:'';
		}
	//	dd($userid ,$zhiyuanName);
		//工序代码   -- FApproveNo
		//$lpsl --数量
		$tempData = [];
		
		if(sqlsrv_begin_transaction($this->SqlServer) == false) {
			die(print_r(sqlsrv_errors(), true));
		}
		
		$ICMakeFlowEntryMXData = [
				"FInterID" => 0,
				"FEntryID" => 1,
				"FItemIDNumber" => $gxcode,
				"FItemIDName" =>$gxname ,
				"FDateSC" => getCurrentTime(),
				"FEntryText1" => $fentrytext1,
				"FQtyLP" => $lpsl ,
				"FQtyBLP" =>  $blpsl ,
				
				"Fqtyblpnr" => $blpnr ,
				"FBLYY" => $blpnr ,
				"FEntryText1" => $fentrytext1,
				"FEntryText2" =>$zhiyuanname ,
				"FHourYC" => 0,
				"FHourSJ" => 0,
				"FJSGXName" =>'',
				"FJSGXCode" => '',
				"FHourPrice" => 0,
				"FHourAmount" => 0,
				
				"FPlanPrice" => $wlprice,
				"FPlanAmount" => $lpsl*$wlprice, // 金额
				"FBillerID" => 16394,
				"FEntryIDD" => 1,
				"YCRemark"=> $ycremark,
				"fnote"=> $fnote,
				'betweentime'=>'',
				"fbatchno" =>  $fbatchno ,
				"FWGCJ" =>  $fwgcj ,
			 
				"fempcode"=>(string)$userid,
				"fyear"=>$fyear,
				"fperiod"=>$fperiod,
				"fcustitemname"=>$fcustitemname,//操作人
				'fgongxu'=>$fgongxu,
		];
	 
		$ICMakeFlowEntryMXins = SqlServerUtil::sqlsrvCreate($this->SqlServer, "gz_gzzyjj", $ICMakeFlowEntryMXData);
		if($ICMakeFlowEntryMXins){
			sqlsrv_commit($this->SqlServer);
			showMsg(200,'成功');
			
		}else {
			sqlsrv_rollback($this->SqlServer);
			showMsg(400,'失败');
		}
		
	}
	
	
	public function  wgUpdate(Request $request){
		$fbatchno = $request->get('fbatchno')?$request->get('fbatchno'):'';//完工批号
		$loginname = $request->get('fname');//登录名称
		$gxcode = $request->get('fitemidnumber')?$request->get('fitemidnumber'):'';//工序代码
		$gxname = $request->get('fitemidname')?$request->get('fitemidname'):'';//工序名称
		$fgongxu = $request->get('fgongxu')?$request->get('fgongxu'):'';//工序名称
		
		$lpsl = $request->get('fqtylp')?$request->get('fqtylp'):0;
		$blpsl = $request->get('fqtyblp')?$request->get('fqtyblp'):0;
		$fentrytext1 = $request->get('fentrytext1')?$request->get('fentrytext1'):'';//机台号
		$ycremark = $request->get('ycremark')?$request->get('ycremark'):'';//异常备注
		$fnote = $request->get('fnote')?$request->get('fnote'):'';//异常备注
		$blpnr = $request->get('fqtyblpnr')?$request->get('fqtyblpnr'):'';
		$userid = $request->get('fempcode')?$request->get('fempcode'):0;//职员编号
		$fwgcj = $request->get('fwgcj')?$request->get('fwgcj'):'';//完工车间
		$username = $request->get('fentrytext2')?$request->get('fentrytext2'):'';//名字
		$fcustitemname = $request->get('fcustitemname')?$request->get('fcustitemname'):'';//名字
		
		$fyear = $request->get('fyear')?$request->get('fyear'):date('y',time());//名字 -- id
		$fperiod = $request->get('fperiod')?$request->get('fperiod'):intval(date('m',time()));//名字
		
		$fplanprice = $request->get('fplanprice')?$request->get('fplanprice'):0;//名字
		
		
		$fid = $request->get('fid');
		if(empty($fid)){
			showMsg(400,'参数错误！');
		}
		
		if(empty($loginname)){
			showMsg(400,'登录名称不能为空');
		}
		//判断
		if(empty($fbatchno)){
			showmsg(400,'批次号不能为空');
		}
// 		$temp = "select FBatchNo,fid form gz_ICMakeFlowEntryMX where FBatchNo ='{$FBatchNo}'  ";
// 		if(!empty($temp['FBatchNo'])){
// 			showMsg(400,'批次号已存在');
// 		}
		
		$wl = SqlServerUtil::exec($this->SqlServer,"select fplanprice,fname,fnumber from gz_wuliao where fnumber ='{$gxcode}'",2);
		if(empty($wl)){
			showMsg(400,'工序名称不存在');
		}
		//$wlprice = $wl['fplanprice']?$wl['fplanprice']:0;
		$wlpricesj = $fplanprice;
		
		if($userid){
			$zyname = SqlServerUtil::exec($this->SqlServer,"select fname from gz_emp where fnumber ='{$userid}'",2);
			$zhiyuanname =  isset($zyname['fname'])?$zyname['fname']:'';
		}
		
		if($username){
			$zyname = SqlServerUtil::execToSql($this->SqlServer,"select fname,fnumber from gz_emp where fitemid ='{$username}'",2);
			$userid =  isset($zyname['fnumber'])?$zyname['fnumber']:'';
			$zhiyuanname = isset($zyname['fname'])?$zyname['fname']:'';
		}
		
// 		if(empty($FPlanPrice) ){
// 			//工序代码   -- FApproveNo
// 			//$lpsl --数量
// 			$tempData = [];
// 			$wlpricesj =0;
// 			$wlprice=0;
// 			if(empty($wl['FApproveNo'])){
// 				$wlprice = $wl['fplanprice']?$wl['fplanprice']:0;
// 				$wlpricesj = $wlprice;
// 			}else{
// 				$tempData = explode('/', $wl['FApproveNo']);
// 				//dd($tempData);
// 				foreach ($tempData as $k =>$v )
// 				{
// 					$start =0;
// 					$wlpricesj = 0;
// 					$end= 0;
// 					$strTemp='';
// 					if(strpos($v,'-') !== false ){
// 						list($strTemp,$wlpricesj) = explode('_', $v );
// 						list($start ,$end) = explode('-', $strTemp );
// 						if($start<= $lpsl && $lpsl < $end){
// 							break;
// 						}else{
// 							$wlpricesj = 0;
// 						}
// 					}else{
// 						if($k == 0 ){
// 							list($start ,$wlpricesj) = explode('_', $v );
// 							//dd($v, $lpsl , $start,$lpsl < $start);
// 							if( $lpsl < $start){
								
// 								break;
// 							}else{
// 								$wlpricesj = 0;
// 							}
							
// 						}else{
// 							list($start ,$wlpricesj) = explode('_', $v );
// 							if( $lpsl >= $start){
// 								break;
// 							}else{
// 								$wlpricesj = 0;
// 							}
// 						}
// 					}
// 				}
// 			}
		
// 		}else{
			
// 			$wlpricesj = $FPlanPrice;
// 		}
		
		
		if(sqlsrv_begin_transaction($this->SqlServer) == false) {
			die(print_r(sqlsrv_errors(), true));
		}
		
		$ICMakeFlowEntryMXData = [
				"FInterID" => 0,
				"FEntryID" => 1,
				"FItemIDNumber" => $gxcode,
				"FItemIDName" =>$gxname ,
				//"FDateSC" => getCurrentTime(),
				"FEntryText1" => $fentrytext1,
				"FQtyLP" => $lpsl ,
				"FQtyBLP" =>  $blpsl ,
				
				"Fqtyblpnr" => $blpnr ,
				"FBLYY" => $blpnr ,
				"FEntryText1" => $fentrytext1,
				"FEntryText2" =>$zhiyuanname ,
				"FHourYC" => 0,
				"FHourSJ" => 0,
				"FHourYC" => 0,
				"FHourYC" => 0,
				"FJSGXName" =>'',
				"FJSGXCode" => '',
				"FHourPrice" => 0,
				"FHourAmount" => 0,
				
				"fplanprice" => $fplanprice,
				"fplanamount" => $lpsl*$fplanprice,
				"fbillerid" => 16394,
				"FEntryIDD" => 1,
				"ycremark"=> $ycremark,
				"fnote"=> $fnote,
				'betweentime'=>'',
				"fbatchno" =>  $fbatchno ,
				 
				"fwgcj"=>$fwgcj,
				"fempcode"=>(string)$userid,
				"fyear"=>$fyear,
				"fperiod"=>$fperiod,
				"fcustitemname"=>$fcustitemname,//操作人
				"fgongxu"=>$fgongxu,
		];
		
		$ICMakeFlowEntryMXins = SqlServerUtil::exeupdateTosql($this->SqlServer, "gz_gzzyjj ", $ICMakeFlowEntryMXData,['fid'=>$fid]);
		if($ICMakeFlowEntryMXins){
			sqlsrv_commit($this->SqlServer);
			showMsg(200,'成功');
			
		}else {
			sqlsrv_rollback($this->SqlServer);
			showMsg(400,'失败');
		}
		
	}
	
	
	
	/**
	* 聚一科技 ^_^
	* @date: 2020年10月26日
	* @author: lq
	* @version:App V2.0
	*/
	public function getMenu(Request $request){
		//菜单列表
		$sql = "select fobjecttype,fobjectid,fname,fdescription from gz_objecttype where fobjecttype>=90000 and fobjectid=0 and fobjecttype in (select distinct fobjecttype from gz_objectfunc where FObjHide=0) order by fobjecttype,fobjectid";
		$menuData = SqlServerUtil::execToSql($this->SqlServer, $sql);
		
		$sql1 = "select distinct t1.fobjecttype,t1.fobjectid,t1.fname,t1.fdescription from gz_objecttype t1 where   t1.fobjectid>0 and t1.fobjectid in (select distinct fobjectid from gz_objectfunc where FObjHide=0 and FIndex=0) order by t1.fobjecttype,t1.fobjectid";
		$menulistData = SqlServerUtil::execToSql($this->SqlServer, $sql1);
		$result=[];
		if($menuData && $menulistData){
			foreach ($menuData as $k=>$v )
			{
				foreach ($menulistData as $k1=>$v1 )
				{
					if($v['fobjecttype'] == $v1['fobjecttype']){
						$menuData[$k]['child'][] = $v1;
					} 
				}
			}
			showMsg(0,'成功',$menuData );
		}
		showMsg(1,'数据为空重新设置');
	}
	
	public function getMenuDetail(Request $request){
		$fobjecttype = $request->get('fobjecttype');
		$fobjectid = $request->get('fobjectid');
		if(empty($fobjecttype) || empty($fobjectid)){
			showMsg(1,'参数错误，请重试！');
		}
		$sql = "select FObjectType,FObjectID,FIndex,FAccessMask,FName from gz_objectaccesstype where fobjecttype='{$fobjecttype}' and fobjectid='{$fobjectid}' order by findex";
		$menulist = SqlServerUtil::execToSql($this->SqlServer, $sql);
		
		showMsg(0,'成功',$menulist );
	}
	
	/**
	* //授权确认   。。 权限 授权
	* @date: 2022年10月27日 上午11:48:36
	* @author: juyi
	*/
	public function sqInsert(Request $request){
		$type = $request->get('type')?$request->get('type'):1;//1-用户 ， 2---组
		$fobjecttype = $request->get('fobjecttype');
		$fobjectid = $request->get('fobjectid');
		$fuserid = $request->get('fuserid');
		$faccesstype = $request->get('faccesstype')?$request->get('faccesstype'):1;
		$faccessmask = $request->get('faccessmask');  //总和
		$Fsqlist = $request->get('fsqlist');  //授权
		$all= $request->all();
		$opername =  $request->get('opername')? $request->get('opername'):'';
		 
		if(empty($fobjectid) || empty($fuserid) || empty($fobjecttype) ){
			showMsg(1,'参数错误');
		}
		//判断 - 职员是否已添加
		
// 		$menulistData = SqlServerUtil::execToSql($this->SqlServer, "select count(1) as cnt  from gz_user_group where groupid = '{$fuserid}'" ,2);
// 		if($menulistData['cnt'] <1){
// 			showMsg(1,'权限组为空，请先添加职员，再赋予权限');
// 		}
		if(sqlsrv_begin_transaction($this->SqlServer) == false) {
			die(print_r(sqlsrv_errors(), true));
		}
		$ins =true;
		unset($all['db']);
		unset($all['opername']);
		unset($all['type']);
		if($type == 1){
			$del = sqlsrv_query($this->SqlServer, "delete from gz_accesscontrol where fobjecttype ='{$fobjecttype}' and fobjectid ='{$fobjectid}' and fuserid ='{$fuserid}' ");
			$ins = SqlServerUtil::sqlsrvCreateTosql($this->SqlServer,'gz_accesscontrol',$all);
		}elseif($type == 2){
			$del = sqlsrv_query($this->SqlServer, "delete from gz_AccessControl_group where fobjecttype ='{$fobjecttype}' and fobjectid ='{$fobjectid}' and fuserid ='{$fuserid}' ");
			if(!empty($Fsqlist) && $Fsqlist !==null){
				$ins = SqlServerUtil::sqlsrvCreateTosql($this->SqlServer,'gz_AccessControl_group',$all);
			}
			
		}
		//gz_AccessControl_group
		if($ins && $del){
			$this->writeLog('权限设置','权限' , 13001 ,  $all , $opername  );
			sqlsrv_commit($this->SqlServer);
			showMsg(0,'成功');
			
		}else {
			sqlsrv_rollback($this->SqlServer);
			showMsg(1,'失败');
		}
	}
	
	//创建组
	public function createGroup(Request $request)
	{
		$groupname = $request->get('groupname');
		$id = $request->get('id');
		$opername   = $request->get('opername') ? $request->get('opername'):'';
		$data = $request->all();
		
		if(empty($groupname)){
			returnData(1, '组名不能为空');
		}
		$group = SqlServerUtil::execToSql($this->SqlServer, "select * from gz_group where fname ='{$groupname}'",2);
		if(empty($group)){
			if($id == 0){
				$ins = SqlServerUtil::sqlsrvCreateTosql($this->SqlServer,'gz_group',['fname'=>$groupname]);
				if($ins){
					$this->writeLog('权限设置','新增' , 13001 ,$data,$opername );
					showMsg(0,'创建成功');
				}else{
					showMsg(1,'创建失败');
				}
			}else{
				$ins = SqlServerUtil::sqlexecTosql($this->SqlServer,"update gz_group set fname = '{$groupname}' where id = {$id} "  );
				if($ins){
					$this->writeLog('权限设置','权限组重命名' , 13001 ,$data ,$opername  );
					showMsg(0,'修改成功');
				}else{
					showMsg(1,'修改失败');
				}
				
			}
			
		}else{
			showMsg(1,'组名已存在');
		}
	}
	
	//删除组
	public function delGroup(Request $request)
	{
		//$db= $request->get('biaoming');//表名
		$FItemID = $request ->get('id');//组id
		$groupname = $request->get('groupname');
		$opername = $request->get('opername')? $request->get('opername'):'';
		$data = $request->all( );
		
		if(empty($FItemID)){
			returnData(1, '组名参数错误');
		}
		if(sqlsrv_begin_transaction($this->SqlServer) == false) {
			die(print_r(sqlsrv_errors(), true));
		}
		SqlServerUtil::sqlsrvDelete($this->SqlServer,'gz_ObjectAccessField',[ 'fgroupid' =>$FItemID]);
		
		$qkid = sqlsrv_query($this->SqlServer,"DELETE gz_group WHERE id= '{$FItemID}' and id !=1");
		$qkid1 = sqlsrv_query($this->SqlServer,"DELETE gz_user_group WHERE groupid = '{$FItemID}' and userid !=1 and groupid !=1  ");
		$qkid2 = sqlsrv_query($this->SqlServer,"DELETE gz_AccessControl_group WHERE FUserID = '{$FItemID}' ");
		if($qkid && $qkid1 && $qkid2){
			$this->writeLog('权限设置','删除' , 13001 ,  $data  ,$opername );
			sqlsrv_commit($this->SqlServer);
			showMsg(0,'删除成功');
		}else{
			sqlsrv_rollback($this->SqlServer);
			showMsg(1,'删除失败');
		}
	}
	
	
	//组列表
	public function getGroupList(Request $request)
	{
		$sqlStr = "select  row_number () OVER ( ORDER BY g.id ) AS rownumber, g.id,g.fname from gz_group g ";
		$Temp = SqlServerUtil::execToSql($this->SqlServer, $sqlStr);
		if($Temp){
			showMsg(0,'成功',$Temp);
		}else{
			showMsg(1,'获取为空');
		}
	}
	
	public function getGroupData(Request $request)
	{
		$groupname = $request->get('groupname');
		$groupStr='';
		if ($request->has('groupname') and $request->groupname != '' and !empty($request->groupname)) {
			$groupStr=" and g.fname = '{$groupname}'";
		}
		//$sqlStr = "select g.* from gz_group g left join gz_user_group ug on g.id= ug.groupid left join gz_admin u on u.id= ug.userid where 1=1 ";
		//,ug.groupid ,g.fname
		$sql="select ug.userid, u.username ,ug.groupid ,g.fname from gz_user_group ug left join gz_group g on g.id= ug.groupid left join gz_admin u on u.id= ug.userid where 1=1 and u.status =1 {$groupStr}";
		$TempArr = SqlServerUtil::execToSql($this->SqlServer, $sql);
		//查询 所有登录用户
		$ids='';
		if(!empty($TempArr)){
			$ids = ' and id not in ('.implode(',',array_column($TempArr, 'userid')).')';
		}
		if($groupname  == '系统管理员组'){
			$loginData = SqlServerUtil::execToSql($this->SqlServer, "select id userid,username from gz_admin where 1=1 and status =1 {$ids} ");
		}else{
			$loginData = SqlServerUtil::execToSql($this->SqlServer, "select id userid,username from gz_admin where 1=1 and status =1 and username != 'manager'  {$ids} ");
		}	
		$result =[];
		
		$result['yydata'] = $TempArr;
		$result['wydata'] = $loginData;
	 
		showMsg(0,'成功',$result);
		
	}
	
	//用户添加属于组名 --- 保存
	public function userToGroup(Request $request)
	{
		$userids = $request->get('userids'); //用户id
		$groupid = $request->get('groupid'); //组 id 
		if(empty($groupid)){
			showMsg(1,'组名不能为空');
		}
		
		$temp=[];
		$result=[];
		$adminId  =  SqlServerUtil::execToSql($this->SqlServer, "select id from gz_admin where username ='manager' " ,2);
		if(empty($adminId)){
			showMsg(400,'参数错误');
		}
		$ADid = $adminId['id'];
		// 存在 里面
		if(!empty($userids)){
			//查询
			if($groupid == 1){
				sqlsrv_query($this->SqlServer, "delete from gz_user_group where groupid ='{$groupid}'  and userid != '{$ADid}'  " );
			}else{
				// 判断  gz_AccessControl_group 组权限为空
// 				$acData = SqlServerUtil::execToSql($this->SqlServer, "select count(1) as cnt from gz_user_group where 1=1 and groupid = {$groupid} " ,2 );
// 				if($acData['cnt'] < 1){
// 					sqlsrv_query($this->SqlServer, "delete from gz_AccessControl_group where FUserID ='{$groupid}'  ");
// 				}
				sqlsrv_query($this->SqlServer, "delete from gz_user_group where groupid ='{$groupid}'   ");
			}
			
			$temp = explode(',',$userids) ;
			foreach ($temp as $k =>$v)
			{
				if($groupid == 1){
					if($v != $ADid ){
						$result[$k]['userid']  = $v;
						$result[$k]['groupid']  = $groupid;
					}
				}else{
					$result[$k]['userid']  = $v;
					$result[$k]['groupid']  = $groupid;
				}
				
			}
			if(empty($result)){
				showMsg(0,'成功');
			}
			//echo "delete from gz_user_group where groupid ='{$groupid}' ";die;
			$ins = SqlServerUtil::sqlsrvAllTosql($this->SqlServer,'gz_user_group',$result);
			if($ins){
				showMsg(0,'成功');
			}else{
				showMsg(1,'失败');
			}
		}
		sqlsrv_query($this->SqlServer, "delete from gz_user_group where groupid ='{$groupid}' and userid != '{$ADid}'   ");
// 		sqlsrv_query($this->SqlServer, "delete from gz_AccessControl_group where FUserID ='{$groupid}'  ");
		showMsg(0,'成功');
		
	}
	/**
	 * 聚一科技 ^_^
	 * 权限
	 * @date: 2020年10月26日
	 * @author: lq
	 * @version:App V2.0
	 */
	public function quanxian(Request $request){
		$fapp =$request->get('fapp')?$request->get('fapp'):'SYERP'; //SYERP
		$ffrm =$request->get('ffrm');  //frmMainFlow
		$ffunc =$request->get('ffunc'); //13000
		$Fname =$request->get('fname'); //
		
		$authinfo = $this->checkaccessright('SYERP',$ffrm,$ffunc,$Fname);
		if($authinfo === true){
			returnData(0, '成功');
		}else{
			returnData(1, $authinfo);
		}
	}
	
	public function  checkaccessright($fapp,$ffrm,$ffunc,$Fname){
		$FObjectType = "";
		$FObjectID = "";
		$FAccessMask = "";
		$FAccessMaskV = "";
		$FGroupID = "";
		$data =[];
		//获取功能模块id、功能id、权限码
		$sql = "select FObjectType,FObjectID,FAccessMask from gz_objectfunc where fapp='{$fapp}' and ffrm='{$ffrm}' and ffunc='{$ffunc}' and findex > 0  ";
		$res = SqlServerUtil::execTosql($this->SqlServer, $sql);
		if(empty($res)) return '功能模块参数错误';
		if($res && count($res)>0){
			$FObjectType = $res[0]['FObjectType']; //90000
			$FObjectID = $res[0]['FObjectID']; //13000
			$FAccessMask = $res[0]['FAccessMask']; //1
		}
		
		if ($FAccessMask !=""){
			//检测是否系统管理员组用户
			$sql = "select gz_admin.id from gz_user_group, gz_admin where gz_user_group.userid = gz_admin.id And gz_admin.username = '{$Fname}' and gz_admin.status =1 and gz_user_group.groupid = 1";
			$res = SqlServerUtil::execTosql($this->SqlServer, $sql);
			if($res && count($res)>0){
				return true;
			}
			
			//查出当前用户当前功能具备的权限值 判断是否与功能权限码匹配
			$sql="select gz_accesscontrol.* from gz_accesscontrol,gz_admin where gz_accesscontrol.FUserID = gz_admin.id  And gz_admin.username = '{$Fname}' gz_admin.status =1 and FObjectType = '{$FObjectType}' and FObjectID = '{$FObjectID}'";
			$res = SqlServerUtil::execTosql($this->SqlServer, $sql);
			if($res && count($res)>0){
				$FAccessMaskV = $res[0]['FAccessMask'];
				if (($FAccessMaskV & $FAccessMask) == $FAccessMask) { //用户自身具备权限
					return true;
				}
			}
			//查出当前用户所在组的当前功能具备的权限值 判断是否与功能权限码匹配
			$sql = "SELECT 	ug.userid, u.username ,ug.groupid ,g.fname
			FROM gz_user_group ug LEFT JOIN gz_group g ON g.id = ug.groupid LEFT JOIN gz_admin u ON u.id = ug.userid
			WHERE 1 = 1 and u.username = '{$Fname}' u.status =1";
			$res = SqlServerUtil::execTosql($this->SqlServer, $sql);
			if($res && is_array($res)){
				foreach ($res as $k =>$v)
				{
					$res2=[];
					//$v['groupid'] 
					$sql = "select * from gz_accesscontrol_group where fuserid='{$v['groupid']}' and FObjectType = '{$FObjectType}' and FObjectID = '{$FObjectID}'";
					$res2 = SqlServerUtil::execTosql($this->SqlServer, $sql);
					if($res2 && count($res2)>0){
						$FAccessMaskV = $res2[0]['FAccessMask'];
						if (($FAccessMaskV & $FAccessMask) == $FAccessMask) { //用户自身具备权限
							return true;
						}
					}
				}
			}
		}
		$sql_1 ="select FName from gz_ObjectFunc where FObjectType = '{$FObjectType}' and FObjectID = '{$FObjectID}' and FIndex =0";
		$res_1 = SqlServerUtil::exec($this->SqlServer, $sql_1,2);
		$FName1 = $res_1['FName']?$res_1['FName']:'列表查询';
		$sql_2 ="select FName from gz_ObjectFunc where FObjectType = '{$FObjectType}' and FObjectID = '{$FObjectID}' and FFunc ='{$ffunc}'";
		$res_2 = SqlServerUtil::exec($this->SqlServer, $sql_2,2);
		$FName2 = $res_2['FName']?$res_2['FName']:'新增';
		return '您没有当前操作权限 ('.$FName1.'-'.$FName2.')';
	}
	
	/**
	* 聚一科技 ^_^  
	* @date: 2020年10月27日
	* @author: lq
	* @version:App V2.0
	*/
	public function jichuData(Request $request){
		$typeid = $request->get('typeid');
		$Data =[];$Data2 =[];
		if($typeid == 30){
			//部门名称 30
			$sql_1= "SELECT finterid,fname,ftypeid,fid FROM gz_submessage where FTypeID= 30 order by ftypeid ,fid ";
		}elseif ($typeid ==  23){
			//学历 23
			$sql_1="select finterid,fname,ftypeid,fid from gz_submessage where FTypeID= 23 order by ftypeid ,fid";
		}elseif ($typeid == 29){
			//职务 29
			$sql_1="select finterid,fname,ftypeid,fid from gz_submessage where FTypeID= 29 order by ftypeid ,fid";
		}elseif ($typeid == 102){
			//性别 102
			$sql_1="select finterid,fname,ftypeid,fid from gz_submessage where FTypeID= 102 order by ftypeid ,fid";
		}elseif ($typeid == 26){
			//区域 26
			$sql_1="select finterid,fname from gz_submessage where FTypeID= 26 order by ftypeid ,fid";
		}elseif ($typeid == 200){
			//离职 200
			$sql_1="select finterid,fname from gz_submessage where FTypeID= 200 order by ftypeid ,fid";
		}elseif ($typeid == 301){
			//单位  301
			$sql_1="select finterid,fname from gz_submessage where FTypeID= 301 order by ftypeid ,fid";
		}elseif ($typeid == 302){
			//公司名称  302
			$sql_1="select finterid,fname from gz_submessage where FTypeID= 302 order by ftypeid ,fid";
		}elseif ($typeid == 303){
			//币种  303
			$sql_1="select finterid,fname from gz_submessage where FTypeID= 303 order by ftypeid ,fid";
		}else{
			$sql_1="SELECT finterid ,fname,ftypeid,fid FROM gz_submessage where FTypeID= 30 
			UNION all
			select finterid,fname,ftypeid,fid from gz_submessage where FTypeID= 23    
			UNION all
			select finterid,fname,ftypeid,fid from gz_submessage where FTypeID= 29  
			UNION all
			select finterid,fname,ftypeid,fid from gz_submessage where FTypeID= 102  
			UNION all
			select finterid,fname,ftypeid,fid from gz_submessage where FTypeID= 26
			UNION all
			select finterid,fname,ftypeid,fid from gz_submessage where FTypeID= 301  
			UNION all 
			select finterid,fname,ftypeid,fid from gz_submessage where FTypeID= 302
			UNION all
			select finterid,fname,ftypeid,fid from gz_submessage where FTypeID= 303   
			UNION all
			select finterid,fname,ftypeid,fid from gz_submessage where FTypeID= 200 order by ftypeid ,fid ";
			
			$Data = SqlServerUtil::exec($this->SqlServer,$sql_1);
			$temp=['23'=>'fdegree','29'=>'fduty','30'=>'fdepid','102'=>'fgender','26'=>'quyu','200'=>'fdeletedid','301'=>'funit','302'=>'fcompany','303'=>'fcurrency'];
			if($Data){
				foreach ($Data as $k =>$v)
				{
					$Data2[$temp[$v['ftypeid']]][] =$v;
				}
			}
			showMsg(0,'成功',$Data2);
		}
		
		$Data = SqlServerUtil::exec($this->SqlServer,$sql_1);
		showMsg(0,'成功',$Data);
	}
	
	/**
	* 审核1 ，反审核0
	* @date: 2022年10月28日 上午11:06:54
	* @author: juyi
	*/
	public function Fstatus(Request $request){
		$FRepKey = $request->get('FRepKey');
		$loginname = $request->get('loginname');
		
		if(empty($loginname)){
			showMsg(1,'审核名称不能为空');
		}
		$FIDStr='';
		$FItemidStr='';
		if ($request->has('fid') and $request->fid != '' and !empty($request->fid)) {
			$FID = $request->fid;
			$FIDStr=" and fid in ($FID) ";
			$FItemidStr=" and fitemid in ($FID) ";
		}
		
		$db = columnBiao($FRepKey);
		$Fstatus = $request->get('Fstatus'); //1--审核，0--反审
		if($FRepKey == 12011){
			if($request->get('fs') === 1 ){
				if($Fstatus == 0){
					$sql="update {$db} set FFustatus = '{$Fstatus}', fucheckName = '' where 1=1 {$FIDStr}   ";
				}else{
					$sql="update {$db} set FFustatus = '{$Fstatus}', fucheckName = '{$loginname}' where 1=1 {$FIDStr}   ";
				}
			}else{
				if($Fstatus == 0){
					$sql="update {$db} set Fstatus = '{$Fstatus}', checkName = '' where 1=1 {$FIDStr}   ";
				}else{
					$sql="update {$db} set Fstatus = '{$Fstatus}', checkName = '{$loginname}' where 1=1 {$FIDStr}   ";
				}
			}
			
		}elseif(in_array($FRepKey, ['12001'  ]) ){
			if($Fstatus == 0){
				$sql="update {$db} set Fstatus = '{$Fstatus}', checkName = '' where 1=1 {$FItemidStr}   ";
			}else{
				$sql="update {$db} set Fstatus = '{$Fstatus}', checkName = '{$loginname}' where 1=1 {$FItemidStr}   ";
			}
			
		}elseif(in_array($FRepKey, [ '27011' ]) ){
			//fstatusCG
			$Fstatus = $request->get('FstatusCG');
			if($Fstatus == 0){
				$sql="update {$db} set FstatusCG = '{$Fstatus}', checkNameCG = '' where 1=1 {$FIDStr}   ";
			}else{
				$sql="update {$db} set FstatusCG = '{$Fstatus}', checkNameCG = '{$loginname}' where 1=1 {$FIDStr}   ";
			}
			
		}elseif(in_array($FRepKey, [ '29001' ]) ){
			//燃油汇总  是否已确认 
			$hzData = $request->data;
			if(empty($hzData)){
				showMsg(400,'请选中当前行流水号订单');
			}
			
			$fbillnoStrTmp = join("','",array_column($hzData,'fbillno'))  ;
			$fbillnoStr = "'".$fbillnoStrTmp ."'";
			$sqlhz =" select fbillno,fisqr,fqrJS from  gz_YBaseSC where fbillno in ({$fbillnoStr}) " ;
			if($Fstatus == 0){
				$sql="update {$db} set Fstatus = '{$Fstatus}', checkName = '' where 1=1 {$FIDStr}   ";
				//判断是否存在多个流水号 审核状态
				$temp = SqlServerUtil::execToSql($this->SqlServer,   $sqlhz  );
				if(!empty($temp)){
					foreach ($temp as $k =>$v)
					{
						if($v['fisqr']==1 || !empty($v['fqrJS'])){
							showMsg(400,'选中流水号订单'.$v['fbillno'].'，技术中心已确认,无法反审');
						}
						if( $v['fisqr']>2   ){
							showMsg(400,'选中流水号订单'.$v['fbillno'].'，财务部已确认,无法反审');
						}
					}
				}
				
			}else{
				$sql="update {$db} set Fstatus = '{$Fstatus}', checkName = '{$loginname}' where 1=1 {$FIDStr}   ";
			}
			
		}elseif(in_array($FRepKey, [ '29010' ]) ){
			//燃油汇总  是否已确认
			$hzData = $request->data;
			if(empty($hzData)){
				showMsg(400,'请选中当前行流水号订单');
			}
			
			$fbillnoStrTmp = join("','",array_column($hzData,'fbillno'))  ;
			$fbillnoStr = "'".$fbillnoStrTmp ."'";
			$sqlhz =" select fbillno,fisqr,fqrJS from  gz_YBaseSC where fbillno in ({$fbillnoStr}) " ;
			if($Fstatus == 0){
				$sql="update {$db} set Fstatus = '{$Fstatus}', checkName = '' where 1=1 {$FIDStr}   ";
				//判断是否存在多个流水号 审核状态
				$temp = SqlServerUtil::execToSql($this->SqlServer,   $sqlhz  );
				if(!empty($temp)){
					foreach ($temp as $k =>$v)
					{
						if($v['fisqr']==1 || !empty($v['fqrJS'])){
							showMsg(400,'选中流水号订单'.$v['fbillno'].'，技术中心已确认,无法反审');
						}
						if( $v['fisqr']>2   ){
							showMsg(400,'选中流水号订单'.$v['fbillno'].'，财务部已确认,无法反审');
						}
					}
				}
				
			}else{
				$sql="update {$db} set Fstatus = '{$Fstatus}', checkName = '{$loginname}' where 1=1 {$FIDStr}   ";
			}
			
		}elseif(in_array($FRepKey, [ '30002' ]) ){
			//正式报价
			$zsData = $request->data;
			foreach ($zsData as $k =>$v)
			{
				if($v['fisqr']>0){
					showMsg(400,'已完成，无法操作');
				}
			}
			
			if(empty($zsData)){
				showMsg(400,'请选中当前行流水号订单');
			}
			$fbillnoStrTmp = join("','",array_column($zsData,'fbillno'))  ;
			$fbillnoStr = "'".$fbillnoStrTmp ."'";
			if($Fstatus == 0){
				$sql="update {$db} set Fstatus = '{$Fstatus}', checkName = '' where 1=1 {$FIDStr}   ";
				//判断是否存在多个流水号 审核状态
				$temp = SqlServerUtil::execToSql($this->SqlServer, "select fbillno,fstatus from gz_YBaseSC_QDHT where 1=1 and fbillno in ({$fbillnoStr})  " );
				if(!empty($temp)){
					showMsg(400,'选中流水号订单，在正式报价后续列表已经存在，请检查');
				}
				
			}else{
				$sql="update {$db} set Fstatus = '{$Fstatus}', checkName = '{$loginname}' where 1=1 {$FIDStr}   ";
				//判断是否存在多个流水号 审核状态
				$temp = SqlServerUtil::execToSql($this->SqlServer, "select fbillno,fstatus from $db where 1=1 and fbillno in ({$fbillnoStr})  and fstatus =1 " );
				if(!empty($temp)){
					showMsg(400,'选中的流水号订单，存在已经审核的订单');
				}
				
			}
			
		}elseif(in_array($FRepKey, ['30010' ]) ){
			if($Fstatus == 0){
				$sql="update {$db} set Fstatus = '{$Fstatus}', checkName = '' where 1=1 {$FIDStr}   ";
				//30010 不能再进行反审  ， 签订合同 审核已经生成了
				$QDHTData = $request->data;
				foreach ($QDHTData as $k =>$v){
					if($v['fisqrname']>0){
						showMsg(400,'已完成无法在操作 ！');
					}
				}
				if($QDHTData){
					 $fbillnoentry =join("','", array_column($QDHTData , 'fbillnoentry'));
					 $fbillnoentryStr = "'".$fbillnoentry ."'";
					$Tmp =  SqlServerUtil::execToSql($this->SqlServer, "select fbillnoentry,fstatus from gz_YbaojiadanCB_QDHT  where 1=1 and fbillnoentry in ({$fbillnoentryStr})" ,2 );
					if($Tmp){
						//判断是否有值
						if($Tmp['fstatus']>0){
							showMsg(400,$v['fbillnoentry'].'签订合同已经审核了，不能再 反审了！');
						}
					 	showMsg(400,'签订合同正式报价已生成，无法反确认，请联系');
					 }
				}
				
			}else{
				$sql="update {$db} set Fstatus = '{$Fstatus}', checkName = '{$loginname}' where 1=1 {$FIDStr}   ";
				//签订合同 审核 对 专利 生成 
				$QDHTData = $request->data;
				foreach ($QDHTData as $k =>$v){
					if($v['fisqrname']>0){
						showMsg(400,'已完成无法在操作 ！');
					}
					if($v['fstatus']>0){
						showMsg(400,'已经审核 ,无法操作！');
					}
				}
				//专利费
				$ZlData = SqlServerUtil::execToSql($this->SqlServer, "select * from gz_Yzhuanlif " );
				//参数设置
				$csSetData = $this->getSystemProfile(['FSetFFAX','FSetZhaunlifeiBL','FSetZhaunlifeiBLMAN']);
				
				if($QDHTData){
					$fbillnoentry =join("','", array_column($QDHTData , 'fbillnoentry'));
					$fbillnoentryStr = "'".$fbillnoentry ."'";
					$Tmp =  SqlServerUtil::execToSql($this->SqlServer, "select fbillnoentry from gz_YbaojiadanCB_QDHT  where 1=1 and fstatus =1 and fbillnoentry in ({$fbillnoentryStr})"  );
					if($Tmp){
						showMsg(400,'签订合同已经审核了，不能再 审核了！');
					}
					
					
					foreach ($QDHTData as $k =>$v)
					{
						//专利确认   getZLValueQDHT
						$zlTemp  = getZLValueQDHT($ZlData ,$v['fmodel'],$v['fbrandjs'],$v['fbillno'],$csSetData['fsetzhaunlifeibl'], $csSetData['fsetzhaunlifeiblman'],$csSetData['fsetffax'],$v['fbillnoentry'] );
						if($zlTemp){
							SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_Yzhuanlif_QDHT' , ['fbillnoentry'=> "'".$v['fbillnoentry']."'" ],true);
							SqlServerUtil::sqlsrvCreate($this->SqlServer ,'gz_Yzhuanlif_QDHT' , $zlTemp);
						}
					}
				}
			}
			
		}elseif(in_array($FRepKey, ['34001' ]) ){
			//正式报价加账业务 - 反审 
			$data = $request->data ;
			if($Fstatus == 0){
				foreach ($data as $k =>$v){
					if($v['fisqr'] >1 ){
						showMsg(400, '流水号子订单：'.$v['fbillnoentry'].' ,技术或采购 或财务 已经确认 ，无法反审！') ;
					}
					if(!empty($v['fqrjs']) ||  !empty($v['fqrcg']) ||  !empty($v['fqrcw'])   ){
						showMsg(400, '流水号子订单：'.$v['fbillnoentry'].' ,无法反审，需财务部门 反确认！') ;
					}
				}
				$sql="update {$db} set Fstatus = '{$Fstatus}', checkName = '' where 1=1 {$FIDStr}   ";
			}else{
				$fmStr ='';
				$fmodelArr = [];
				foreach ($data as $k =>$v){
					if($v['fisjiazhang'] == '是')
					{
						$fmStr .= ','."'".$v['fbillnoentry']."'" ;
						$fmodelArr[]=$v ;
					}
					if($v['fstatus'] == 1){
						showMsg(400,'流水号子订单：'.$v['fbillnoentry'].'，机型：'.$v['fmodel'].' ,已审核，请检查!') ;
					}
					
					//判断业务  -- 加账清单 和 市场需求
					if(  $v['fisjiazhang'] == '是'   ){
						// 1.ICER版本（燃气或者燃油版） 无   ， EGC型号 无 ,  有SCR 或 EGR
						$sql = "select v1.fcode,v1.fprodno,u1.fid,u1.fname,u1.fbrand  from gz_Yjiazhangcbf_HXJZ  v1
						inner join gz_YjiazhangcbfSet u1 on u1.fcode = v1.fcode
						where  fbillnoentry  = '{$v['fbillnoentry']}'  " ;
						$TempData = SqlServerUtil::execToSql($this->SqlServer,$sql  );
						if( empty($TempData)  ){
							showMsg(400, '无法审核，流水号子订单：'.$v['fbillnoentry'].'，没有加账清单，请检查');
						}
						//代码code
						$arrCcode = array_column($TempData, 'fcode'); 
						
						if($v['fmodel'] != $TempData[0]['fprodno']){
							showMsg(400 , '无法审核，流水号子订单：'.$v['fbillnoentry'].' ,业务需求机型与加账清单机型不一致（删掉加账清单重新导入），请检查。 ') ; 
						}
						// 判断 高硫  3.5%   如果硫含量3.5%，把LDCL系统的成本自动放在主机成本总价里。  正式报价加账(业务) -- 34001   暂不控制
// 						if($TempData[0]['fbrand']  == 'MAN'){
// 							if( stripos( $v['fzhujiranliaos'] , '3.5' ) !== false){
// 								if(!in_array('JZM028', $arrCcode)){
// 									showMsg(400, '无法审核，流水号子订单：'.$v['fbillnoentry'].',硫含量'.$v['fzhujiranliaos']. ',LDCL系统未添加，请检查');
// 								}
// 							}
// 						}
						// fisryrq
						if($v['fisryrq']== '无' ){
							// 机型  $v['fmodel'] ，  流水号   $v['fbillno']
							//检验 是否 存在  加账清单 fegcmodel型号
							if($v['fegcmodel'] !='无'){
								showMsg(400,'无法审核，流水号子订单：'.$v['fbillnoentry'].' ，ICER版本（燃气或者燃油版） 选择无 ，与EGC型号不一致 ,请检查！') ;
							}
							$jiazhangdatastr = $v['jiazhangdatastr'] ;
							
							$fegcmodelICER = 'EGC'.$v['fegcmodel'];
							if( $v['fegcmodel'] !='无' ){
								if( !isValueInArrayICER($TempData, $fegcmodelICER )  ){
									showMsg(400, '无法审核，流水号子订单：'.$v['fbillnoentry'].',加账清单 中  iCER ('.$fegcmodelICER .'),与  业务需求选择EGC型号不一致 ， 请检查 ');
								}
							}
							if( $v['fegcmodel'] =='无' || empty($v['fegcmodel']) ){
								$fegcmodelICER_0 = 'EGC' ;
								if( isValueInArrayICER($TempData,$fegcmodelICER_0)  ){
									showMsg(400, '无法审核，流水号子订单：'.$v['fbillnoentry'].' ,加账清单存在 iCER（EGC型号） 与  业务需求选择EGC型号不一致  ，请检查 ');
								}
							}
							
							// 判断 加账清单是否存在SCR
							if($v['fisscr'] == '否'){
								//清单里没有
								if( isValueInArrayICER($TempData,'PSCR')  ){
									showMsg(400, '无法审核，流水号子订单：'.$v['fbillnoentry'].' ,加账清单存在 SCR 与  业务需求选择`是否含SCR`不一致  ，请检查 ');
								}
							}
							
							if($v['fisscr'] !='否'){
								if(strtolower($v['fisscr']) == 'iscr' ){
									if( !isValueInArrayiSCR($TempData ,'iSCR')  ){
										showMsg(400,'加账清单没有选择带iSCR  ，或加账清单基础设置没添加，请检查 ');
									}
								}else{
		
									//清单 必有
									if( !isValueInArrayICER($TempData, 'PSCR' )  ){
										showMsg(400, '无法审核，流水号子订单：'.$v['fbillnoentry'].',  业务需求 选择`是否含SCR`,与加账清单 SCR高低硫 不一致 , 请检查 ');
									}
									if( $v['fisscr'] ==  "LPSCR"){
										if( !isValueInArrayICER($TempData, 'LPSCR' )  ){
											showMsg(400, '无法审核，流水号：'.$v['fbillnoentry'].',  业务需求 选择`是否含SCR`,与加账清单 LPSCR高低硫 不一致 , 请检查 ');
										}
									}
									if( $v['fisscr'] ==  "HPSCR"){
										if( !isValueInArrayICER($TempData, 'HPSCR' )  ){
											showMsg(400, '无法审核，流水号：'.$v['fbillnoentry'].',  业务需求 选择`是否含SCR`,与加账清单 HPSCR高低硫 不一致 , 请检查 ');
										}
									}	
									//选择是否正确
	// 								$fcodeTmp = isHPLPSCRONE($TempData[0]['fbrand'] , $arrCcode) ;
	// 								if( $fcodeTmp=== true){
	// 									showMsg(400,  '加账清单SCR高低硫选择不正确，或选择多个，请检查');
	// 								}
	// 								if(isHPLPSCR($TempData[0]['fbrand'] , $fcodeTmp ,$v['fisscr'],$v['fscrlowup'] )){
	// 									showMsg(400,   '无法审核，流水号子订单：'.$v['fbillnoentry'].',业务需求选择SCR高低硫，加账清单SCR高低硫不一致， 请检查  ');
	// 								}
								}
							}
							
							// 判断 加账清单是否存在 EGR
							if($v['fisegr'] == '否'){
								//清单里没有
								if( isValueInArrayICER($TempData,'EGR')  ){
									showMsg(400, '无法审核，流水号子订单：'.$v['fbillnoentry'].' ,加账清单存在 EGR 与  业务需求选择`是否含EGR`不一致  ，请检查 ');
								}
							}
							
							if($v['fisegr'] !='否'){
								if( !isValueInArrayICER($TempData, 'EGR' )  ){
									showMsg(400, '无法审核，流水号子订单：'.$v['fbillnoentry'].',业务需求 选择 是否含EGR  ，与加账清单不一致，    请检查 ');
								}
								
								//选择是否正确
								if(strtoupper($v['fisegr']) == 'ECOEGR'){
									if( !isValueInArrayICER($TempData, 'EcoEGR' )  ){
										showMsg(400, '无法审核，流水号子订单：'.$v['fbillnoentry'].',业务需求选择 EcoEGR ，与加账清单不一致， 请检查 ');
									}
								}else{
									if( !isValueInArrayICER($TempData, 'EGR' )  ){
										showMsg(400, '无法审核，流水号子订单：'.$v['fbillnoentry'].',业务需求选择 EGR  ，与加账清单不一致 ，请检查 ');
									}
								}
								
							}
							
							// fisryrq
						}else{
							// ICER版本（燃气或者燃油版）   存在 EGC型号
							//1.检验 是否 存在  加账清单 fegcmodel型号
							if($v['fegcmodel'] == '无'){
								showMsg(400,'无法审核，流水号子订单：'.$v['fbillnoentry'].' ，选择ICER版本（燃气或者燃油版）   ，与EGC型号不一致 ,请检查！') ;
							}
							$fegcmodelICER = 'EGC'.$v['fegcmodel'];
							if( $v['fegcmodel'] !='无' ){
								if( !isValueInArrayICER($TempData, $fegcmodelICER )  ){
									showMsg(400, '无法审核，流水号子订单：'.$v['fbillnoentry'].',加账清单 没有选择 iCER ('.$fegcmodelICER .'),与  业务需求市选择EGC型号不一致 ， 请检查 ');
								}
							}
							
							//2.SCR
							if($v['fisscr'] == '否'){
								//清单里没有
								if( isValueInArrayICER($TempData,'PSCR')  ){
									showMsg(400, '无法审核，流水号子订单：'.$v['fbillnoentry'].' ,加账清单存在 SCR 与  业务需求选择`是否含SCR`不一致  ，请检查 ');
								}
							}
							//3.EGR
							if($v['fisegr'] == '否'){
								//清单里没有,
								if( isValueInArrayICER($TempData,'EGR')  ){
									showMsg(400, '无法审核，流水号子订单：'.$v['fbillnoentry'].' ,加账清单存在 EGR 与  业务需求选择`是否含EGR`不一致  ，请检查 ');
								}
							}
							
						}
					
					}else{
						//无加账 
						//判断是否存在加账 
						$sql = "select v1.fcode,u1.fid,u1.fname,u1.fbrand  from gz_Yjiazhangcbf_HXJZ  v1
						inner join gz_YjiazhangcbfSet u1 on u1.fcode = v1.fcode
						where  fbillnoentry  = '{$v['fbillnoentry']}'  " ;
						$TempData = SqlServerUtil::execToSql($this->SqlServer,$sql  );
						if( !empty($TempData)  ){
							showMsg(400, '无法审核，流水号子订单：'.$v['fbillnoentry'].'，已存在加账清单，请检查');
						}
						
					}
					
				}
				
				
// 				if(!empty($fmStr)){
// 					//判断是否已经加账 -- 审核
// 					$fbillnoentryStr = trim($fmStr ,',');
// 					$a1 = " select distinct fbillnoentry  from gz_Yjiazhangcbf_HXJZ where fbillnoentry  in ({$fbillnoentryStr}) ";
// 					//echo $a1;die;
// 					$aTemp = SqlServerUtil::execTosql($this->SqlServer, $a1 );
// 					if(empty($aTemp)){
// 						showMsg(400, '无法审核，'.$fbillnoentryStr.' 没有添加加账清单，请检查！');
// 					}
// 					$arr2 = array_column($aTemp, 'fbillnoentry');
// 					$arr1 = array_column($fmodelArr, 'fbillnoentry');
// 					$arrayDiff = array_diff($arr1 ,$arr2 ) ;
// 					if($arrayDiff){
// 						showMsg(400, join(',',$arrayDiff).' 没有添加加账清单，请检查!!!');
// 					}
// 				}
				
				
				$sql="update {$db} set Fstatus = '{$Fstatus}', checkName = '{$loginname}' where 1=1 {$FIDStr}   ";
			}
			
		}elseif(in_array($FRepKey, ['14009' ]) ){
			//正式 报价 业务
			$data = $request->data ;
			if($Fstatus == 0){
				foreach ($data as $k =>$v){
					if($v['fisqrname']>0){
						showMsg(400,'流水号：'.$v['fbillno'].'，已完成 ，无法操作！') ;
					}
					if($v['fisqr'] >1 ){
						showMsg(400,'流水号：'.$v['fbillno'].' ，技术、采购 、财务 已经确认 ，无法反审！') ;
					}
					if(!empty($v['fqrjs']) ||  !empty($v['fqrcg']) ||  !empty($v['fqrcw'])   ){
						showMsg(400,'流水号：'.$v['fbillno'].' ，无法反审，需财务部门 反确认！') ;
					}
					SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_YranyouHZ_BAOJIA' , ['fjybjbillno'=> "'".$v['fbillno']."'" ],true);
					SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_YranyouHZ' , ['fbillno'=> "'".$v['fbillno']."'" ],true);
				}
				
				$sql="update {$db} set Fstatus = '{$Fstatus}', checkName = '' where 1=1 {$FIDStr}   ";
			}else{
				//gz_Yjiazhangcbf   fisjiazhang
				$fmStr ='';
				$fmodelArr = [];
				$csSetData = $this->getSystemProfile(['FSetHwtsSMS', 'FSetCjsSMS']);
				$tsfTmp = explode(',', $csSetData['fsethwtssms'] );
				$cjffTmp = explode(',', $csSetData['fsetcjssms'] );
				
				$controller = app('App\Http\Controllers\Api\SmsController');
// 				dd( $csSetData );
				foreach ($data as $k =>$v){
				    
					if($v['fisqrname']>0){
						showMsg(400,'已完成 ，无法操作！') ;
					}
					if($v['fisjiazhang'] == '是')
					{
						$fmStr .= ','."'".$v['fbillno']."'" ; 
						$fmodelArr[]=$v ;
					}
					if($v['fstatus'] == 1){
						showMsg(400,'流水号：'.$v['fbillno'].'，机型：'.$v['fmodel'].' ,已审核!') ;
					}
					
					//判断业务  -- 加账清单 和 市场需求
					if(  $v['fisjiazhang'] == '是'   ){
						// 1.ICER版本（燃气或者燃油版） 无   ， EGC型号 无 ,  有SCR 或 EGR  
						$sql = "select v1.fcode,v1.fprodno,u1.fid,u1.fname,u1.fbrand  from gz_Yjiazhangcbf v1
						inner join gz_YjiazhangcbfSet u1 on u1.fcode = v1.fcode
						where  fbillno  = '{$v['fbillno']}'  " ;
						$TempData = SqlServerUtil::execToSql($this->SqlServer,$sql  );
						if( empty($TempData)  ){
							showMsg(400, '无法审核，流水号：'.$v['fbillno'].'，没有加账清单，请检查');
						}
						//代码code 
						$arrCcode = array_column($TempData, 'fcode'); 
						if($v['fmodel'] != $TempData[0]['fprodno']){
							showMsg(400 , '无法审核，流水号：'.$v['fbillno'].' ,业务需求机型与加账清单机型不一致（删掉加账清单重新导入），请检查。 ') ;
						}
						
						// 判断 高硫  3.5%   如果硫含量3.5%，把LDCL系统的成本自动放在主机成本总价里。
						if($TempData[0]['fbrand']  == 'MAN'){
							if( stripos( $v['fzhujiranliaos'] , '3.5' ) !== false){
								if(!in_array('JZM028', $arrCcode)){
									showMsg(400, '无法审核，流水号：'.$v['fbillno'].',硫含量'.$v['fzhujiranliaos']. ',LDCL系统未添加，请检查');
								}
							}
						}
						// fisryrq 
						if($v['fisryrq']== '无' ){
							// 机型  $v['fmodel'] ，  流水号   $v['fbillno']
							//检验 是否 存在  加账清单 fegcmodel型号
							if($v['fegcmodel'] !='无'){
								showMsg(400,'无法审核，流水号：'.$v['fbillno'].' ，ICER版本（燃气或者燃油版） 选择无 ，与EGC型号不一致 ,请检查！') ;
							}
							$jiazhangdatastr = $v['jiazhangdatastr'] ;
							
							$fegcmodelICER = 'EGC'.$v['fegcmodel'];
							if( $v['fegcmodel'] !='无' ){
								if( !isValueInArrayICER($TempData, $fegcmodelICER )  ){
									showMsg(400, '无法审核，流水号：'.$v['fbillno'].',加账清单 中  iCER ('.$fegcmodelICER .'),与  业务需求选择EGC型号不一致 ， 请检查 ');
								}
							}
							if( $v['fegcmodel'] =='无' || empty($v['fegcmodel']) ){
								$fegcmodelICER_0 = 'EGC' ;
								if( isValueInArrayICER($TempData,$fegcmodelICER_0)  ){
									showMsg(400, '无法审核，流水号：'.$v['fbillno'].' ,加账清单存在 iCER（EGC型号） 与  业务需求选择EGC型号不一致  ，请检查 ');
								}
							}
							
							// 判断 加账清单是否存在SCR 
							if($v['fisscr'] == '否'){
								//清单里没有
								if( isValueInArrayICER($TempData,'PSCR')  ){
									showMsg(400, '无法审核，流水号：'.$v['fbillno'].' ,加账清单存在 SCR 与  业务需求选择`是否含SCR`不一致  ，请检查 ');
								}
							}
						 	
							if($v['fisscr'] !='否'){
								if(strtolower($v['fisscr']) == 'iscr' ){
									if( !isValueInArrayiSCR($TempData ,'iSCR')  ){
										showMsg(400,'加账清单没有选择带iSCR  ，或加账清单基础设置没添加，请检查 ');
									}
								}else{
									//清单 必有
									if( !isValueInArrayICER($TempData, 'PSCR' )  ){
										showMsg(400, '无法审核，流水号：'.$v['fbillno'].',  业务需求 选择`是否含SCR`,与加账清单 SCR高低硫 不一致 , 请检查 ');
									}
									if( $v['fisscr'] ==  "LPSCR"){
										if( !isValueInArrayICER($TempData, 'LPSCR' )  ){
											showMsg(400, '无法审核，流水号：'.$v['fbillno'].',  业务需求 选择`是否含SCR`,与加账清单 LPSCR高低硫 不一致 , 请检查 ');
										}
									}
									if( $v['fisscr'] ==  "HPSCR"){
										if( !isValueInArrayICER($TempData, 'HPSCR' )  ){
											showMsg(400, '无法审核，流水号：'.$v['fbillno'].',  业务需求 选择`是否含SCR`,与加账清单 HPSCR高低硫 不一致 , 请检查 ');
										}
									}
// 									//选择是否正确
// 									$fcodeTmp = isHPLPSCRONE($TempData[0]['fbrand'] , $arrCcode) ;
// 									if( $fcodeTmp=== true){
// 										showMsg(400,  '加账清单SCR高低硫选择不正确，或选择多个，请检查');
// 									}
// 									if(isHPLPSCR($TempData[0]['fbrand'] , $fcodeTmp ,$v['fisscr'],$v['fscrlowup'] )){
// 										showMsg(400,   '无法审核，流水号：'.$v['fbillno'].',业务需求选择SCR高低硫，加账清单SCR高低硫不一致， 请检查  ');
// 									}
								}
								
							}
							
							// 判断 加账清单是否存在 EGR
							if($v['fisegr'] == '否'){
								//清单里没有
								if( isValueInArrayICER($TempData,'EGR')  ){
									showMsg(400, '无法审核，流水号：'.$v['fbillno'].' ,加账清单存在 EGR 与  业务需求选择`是否含EGR`不一致  ，请检查 ');
								}
							}
							
							if($v['fisegr'] !='否'){
								if( !isValueInArrayICER($TempData, 'EGR' )  ){
									showMsg(400, '无法审核，流水号：'.$v['fbillno'].',业务需求 选择 是否含EGR  ，与加账清单不一致，    请检查 ');
								}
								
								//选择是否正确 
								if(strtoupper($v['fisegr']) == 'ECOEGR'){
									if( !isValueInArrayICER($TempData, 'EcoEGR' )  ){
										showMsg(400, '无法审核，流水号：'.$v['fbillno'].',业务需求选择 EcoEGR ，与加账清单不一致， 请检查 ');
									}
								}else{
									if( !isValueInArrayICER($TempData, 'EGR' )  ){
										showMsg(400, '无法审核，流水号：'.$v['fbillno'].',业务需求选择 EGR  ，与加账清单不一致 ，请检查 ');
									}
								}
								
							}
						  
						// fisryrq 
						}else{
							// ICER版本（燃气或者燃油版）   存在 EGC型号  
							//1.检验 是否 存在  加账清单 fegcmodel型号
							if($v['fegcmodel'] == '无'){
								showMsg(400,'无法审核，流水号：'.$v['fbillno'].' ，选择ICER版本（燃气或者燃油版）   ，与EGC型号不一致 ,请检查！') ;
							}
							$fegcmodelICER = 'EGC'.$v['fegcmodel'];
							if( $v['fegcmodel'] !='无' ){
								if( !isValueInArrayICER($TempData, $fegcmodelICER )  ){
									showMsg(400, '无法审核，流水号：'.$v['fbillno'].',加账清单 没有选择 iCER ('.$fegcmodelICER .'),与  业务需求市选择EGC型号不一致 ， 请检查 ');
								}
							}
							
							//2.SCR 
							if($v['fisscr'] == '否'){
								//清单里没有
								if( isValueInArrayICER($TempData,'PSCR')  ){
									showMsg(400, '无法审核，流水号：'.$v['fbillno'].' ,加账清单存在 SCR 与  业务需求选择`是否含SCR`不一致  ，请检查 ');
								}
							}
							//3.EGR 
							if($v['fisegr'] == '否'){
								//清单里没有,
								if( isValueInArrayICER($TempData,'EGR')  ){
									showMsg(400, '无法审核，流水号：'.$v['fbillno'].' ,加账清单存在 EGR 与  业务需求选择`是否含EGR`不一致  ，请检查 ');
								}
							}
							
						}
					}else{
						//无加账
						//判断是否存在加账
						$sql = "select v1.fcode,u1.fid,u1.fname,u1.fbrand  from gz_Yjiazhangcbf v1
						inner join gz_YjiazhangcbfSet u1 on u1.fcode = v1.fcode
						where  fbillno  = '{$v['fbillno']}'  " ;
						$TempData = SqlServerUtil::execToSql($this->SqlServer,$sql  );
						if( !empty($TempData)  ){
							showMsg(400, '无法审核，流水号：'.$v['fbillno'].'，已存在加账清单，请检查');
						}
						
					}
					
					
					//判断 是否是海外调试费    ， 吴春华  18666107900
					if($v['fishwtsf'] == '是' && $tsfTmp){
						foreach ($tsfTmp as $tk=>$tv)
						{
							$controller->sendSmsData( $tv ,  $v['fbillno'].', 存在海外调试费,请留意！ ');
						}
					}
					//判断 船社级  ,  陈恒永 13928001101 , 谢金泉 15976952559
					if( !in_array($v['fchuanjishe'],['CCS','ABS','LR','BV','DNV','NK' ] )  && $cjffTmp){
						foreach ($cjffTmp as  $cv)
						{
							$controller->sendSmsData( $cv ,  $v['fbillno'].' ,船级社：'.$v['fchuanjishe'].' ,请留意操作！ ');
						}
					}
					
				}
// 				if(!empty($fmStr)){
// 					//判断是否已经加账 -- 审核
// 					$fbillnoStr = trim($fmStr ,',');
// 					$a1 = " select distinct fbillno  from gz_Yjiazhangcbf where fbillno in ({$fbillnoStr}) ";
// 					$aTemp = SqlServerUtil::execTosql($this->SqlServer, $a1 );
// 					if(empty($aTemp)){
// 						showMsg(400, $fbillnoStr.' 没有添加加账清单，请检查！');
// 					}
// 					$arr2 = array_column($aTemp, 'fbillno');
// 					$arr1 = array_column($fmodelArr, 'fbillno');
// 					//差集
// 					$arrayDiff = array_diff($arr1 ,$arr2 ) ;
// 					if($arrayDiff){
// 						showMsg(400, join(',',$arrayDiff).' 没有添加加账清单，请检查！！！');
// 					}
// 				}
				
				$sql="update {$db} set Fstatus = '{$Fstatus}', checkName = '{$loginname}' where 1=1 {$FIDStr}   ";
			}
			///30004
		}elseif(in_array($FRepKey, [ '30004' ]) ){
			//经营报价 
			$zsData = $request->data;
			foreach ($zsData as $k =>$v)
			{
				if($v['fisqr']>0){
					showMsg(400,'已完成，无法操作');
				}
				
			}
			if(empty($zsData)){
				showMsg(400,'请选中当前行流水号订单');
			}
			if($Fstatus == 0){
				$sql="update {$db} set Fstatus = '{$Fstatus}', checkName = '' where 1=1 {$FIDStr}   ";
			}else{
				$sql="update {$db} set Fstatus = '{$Fstatus}', checkName = '{$loginname}' where 1=1 {$FIDStr}   ";
			}
			
		}elseif(in_array($FRepKey, [ '34005' ]) ){
		   // dd($request->all() );
		    //财务 - 加帐 
		    $jzData = $request->data;
		    if(empty($jzData)){
		        showMsg(400,'请选中当前行流水号订单');
		    }
		    
		    foreach ($jzData as $k =>$v)
		    {
		        if($v['fisqrname']>0){
		            showMsg(400,'已完成无法在操作 ！');
		        }
		        $resZSQR  = SqlServerUtil::execToSql($this->SqlServer, "select fbillno,fstatus from gz_YbaojiadanCB_HXJZ  where fbillnoentry ='{$v['fbillnoentry']}' ",2 );
		        if($resZSQR){
		            if( $resZSQR['fstatus']> 0 ){
		                showMsg(400,$v['fbillno'].'正式报价加帐-已审核，无法再反审');
		            }
		            showMsg(400,$v['fbillno'].'正式报价加帐-已生成，先删除再反审');
		        }
		    }
		   
		    if($Fstatus == 0){
// 		        $sql="update {$db} set Fstatus = '{$Fstatus}', checkName = '' where 1=1 {$FIDStr}   ";
		        $sql="update {$db} set  fisqr = 2, fqrCW = '',opernameCW = '',fcreattimeCW =null  where 1=1 {$FIDStr}   ";
		    }else{
		        $sql="update {$db} set Fstatus = '{$Fstatus}', checkName = '{$loginname}' where 1=1 {$FIDStr}   ";
		    }
		    
		}elseif(in_array($FRepKey, [ '34004' ]) ){
			//经营报价
			$zsData = $request->data;
			foreach ($zsData as $k =>$v)
			{
				if($v['fisqr']>0){
					showMsg(400,'已完成，无法操作');
				}
			}
			if(empty($zsData)){
				showMsg(400,'请选中当前行流水号订单');
			}
			if($Fstatus == 0){
				$sql="update {$db} set Fstatus = '{$Fstatus}', checkName = '' where 1=1 {$FIDStr}   ";
			}else{
				$sql="update {$db} set Fstatus = '{$Fstatus}', checkName = '{$loginname}' where 1=1 {$FIDStr}   ";
			}
			 
		}elseif(in_array($FRepKey, [ '30011' ]) ){
			//正式报价(后续)
			$zsData = $request->data;
			foreach ($zsData as $k =>$v)
			{
				if($v['fisqr']>0){
					showMsg(400,'已完成，无法操作');
				}
			}
			
			if(empty($zsData)){
				showMsg(400,'请选中当前行流水号订单');
			}
			 
			if($Fstatus == 0){
				$sql="update {$db} set Fstatus = '{$Fstatus}', checkName = '' where 1=1 {$FIDStr}   ";
			}else{
				$sql="update {$db} set Fstatus = '{$Fstatus}', checkName = '{$loginname}' where 1=1 {$FIDStr}   ";
				//判断是否存在多个流水号 审核状态
			}
			
		}elseif(in_array($FRepKey, ['40005' ]) ){
			// 备件报价(财务部)  
			if($Fstatus == 0){
				$sql="update {$db} set Fstatus5 = '{$Fstatus}', ftypeCheck = 3, checkName = '' where 1=1 {$FIDStr}   ";
			}else{
				$sql="update {$db} set Fstatus5 = '{$Fstatus}', ftypeCheck = 4, checkName = '{$loginname}' where 1=1 {$FIDStr}   ";
			}
			
		}elseif(in_array($FRepKey, ['40004' ]) ){
			// 备件采购部
			if($Fstatus == 0){
				$sql="update {$db} set Fstatus4 = '{$Fstatus}', ftypeCheck = 2, checkName = '' where 1=1 {$FIDStr}   ";
			}else{
				$sql="update {$db} set Fstatus4 = '{$Fstatus}', ftypeCheck = 3, checkName = '{$loginname}' where 1=1 {$FIDStr}   ";
			}
			
		}elseif(in_array($FRepKey, ['40002' ]) ){
			// 备件 技术 部
			if($Fstatus == 0){
				$sql="update {$db} set Fstatus2 = '{$Fstatus}', ftypeCheck = 1, checkName = '' where 1=1 {$FIDStr}   ";
			}else{
				$sql="update {$db} set Fstatus2 = '{$Fstatus}', ftypeCheck = 2, checkName = '{$loginname}' where 1=1 {$FIDStr}   ";
			}
			
		}elseif(in_array($FRepKey, ['25007'  ]) ){
			//船级社其他
			$TMP25007 = $request->data ;
			$fbillno =join("','", array_column($TMP25007, 'fjybjbillno'));
			$fjybjbillno = "'".$fbillno ."'";
			
			$selectData = SqlServerUtil::execTosql($this->SqlServer, "select fqrCW,opernameCW,fisqr,fbillno from gz_YBaseSC where  fqrCW <>'' and fbillno in ({$fjybjbillno}) ");
			if(!empty($selectData) && count($selectData)>0  ){
				showMsg(400,'流水号：'. join("','",array_column($selectData, 'fbillno') )  .' , 业务需求（财务）已做确认操作，无法删除，请检查') ;
			}
			
			if($Fstatus == 0){
				$sql="update {$db} set Fstatus = '{$Fstatus}', checkName = '' where 1=1 {$FIDStr}   ";
			}else{
				$sql="update {$db} set Fstatus = '{$Fstatus}', checkName = '{$loginname}' where 1=1 {$FIDStr}   ";
			}
			
			
		}else{
			
			if($Fstatus == 0){
				$sql="update {$db} set Fstatus = '{$Fstatus}', checkName = '' where 1=1 {$FIDStr}   ";
			}else{
				$sql="update {$db} set Fstatus = '{$Fstatus}', checkName = '{$loginname}' where 1=1 {$FIDStr}   ";
			}
		}
		// 启动事务
		if (sqlsrv_begin_transaction($this->SqlServer) === false) {
			die(print_r(sqlsrv_errors(), true));
		}
		
		$this->writeLog(getMkName($FRepKey),$Fstatus?'审核':'反审核' , $FRepKey ,$request->all() ,$loginname );
// 		echo $sql;die;
		$sqlStr = iconv( 'UTF-8','GBK',$sql);
		$up = sqlsrv_query($this->SqlServer, $sqlStr);
		if($up  ){
			sqlsrv_commit($this->SqlServer);
			showMsg(0,'成功');
		}else {
			sqlsrv_rollback($this->SqlServer);
			showMsg(1,'失败');
		}
		
	}
	
	/**
	* 聚一科技 ^_^
	* 权限组 
	* @date: 2020年10月31日
	* @author: lq
	* @version:App V2.0
	*/
	public function groupToQXDetail(Request $request){
		$FObjectType = $request->get('FObjectType');
		$FObjectID = $request->get('FObjectID');
		$FGroupID = $request->get('FGroupID');
		
		if($FGroupID  == 1){
			$sql = "select id,FObjectType,FIndex,FObjectID,FAccessMask,FName from gz_ObjectAccessType where FObjectType = '{$FObjectType}' and FObjectID = '{$FObjectID}' ";
			$data = SqlServerUtil::execTosql($this->SqlServer,$sql);
			showMsg(0,'成功',$data);
		}else{
			
			$sql = "select id,FObjectType,FIndex,FObjectID,FAccessMask,FName from gz_ObjectAccessType where FObjectType = '{$FObjectType}' and FObjectID = '{$FObjectID}' ";
			$data = SqlServerUtil::execTosql($this->SqlServer,$sql);
			
			$sql1 = "select  FObjectType,FObjectID,FUserID,Fsqlist from gz_AccessControl_group where FObjectType = '{$FObjectType}' and FObjectID = '{$FObjectID}' and FUserID='{$FGroupID}' ";
			$data1 = SqlServerUtil::execTosql($this->SqlServer,$sql1,2);
			if($data1 && is_array($data1)){
				$result =[];
				foreach ($data as $k =>$v){
					$temp =[];
					$temp = explode(',',$data1['Fsqlist']);
					foreach ($temp as $k1=>$v1)
					{
						if($v1 ==$v['FAccessMask']){
							$result[] = $v;
						}
					}
				}
				
				showMsg(0,'成功',$result);
			}
			showMsg(0,'成功',[]);
		}
	}
	
	//系统管理员组
	public function FQXMenu(Request $request){
		$loginname = $request->loginname;//登录名称
		if(empty($loginname)){
			showMsg(1,'传参错误，登录名称');
		}
		//菜单列表
		$sql = "select fobjecttype,fobjectid,fname,fdescription from gz_objecttype where fobjecttype>=90000 and fobjectid=0 and fobjecttype in (select distinct fobjecttype from gz_objectfunc where FObjHide=0) order by fobjecttype,fobjectid";
		$menuData = SqlServerUtil::execToSql($this->SqlServer, $sql);
		$menuTemp = $menuData;
		$sql1 = "select distinct t1.fobjecttype,t1.fobjectid,t1.fname,t1.fdescription from gz_objecttype t1 where  t1.fobjectid>0 and t1.fobjectid in (select distinct fobjectid from gz_objectfunc where FObjHide=0 and FIndex=0) order by t1.fobjecttype,t1.fobjectid";
		$menulistData = SqlServerUtil::execToSql($this->SqlServer, $sql1);
		
		$sql2 = "select FObjectType,FObjectID,FIndex,FAccessMask,FName from gz_objectaccesstype order by findex";
		$menuDetail = SqlServerUtil::execToSql($this->SqlServer, $sql2);
		
		$result=[];
		if($menuData && $menulistData && $menuDetail){
			foreach ($menuData as $k=>$v )
			{
				foreach ($menulistData as $k1=>$v1 )
				{
					if($v['fobjecttype'] == $v1['fobjecttype']){
						$menuData[$k]['children'][] = $v1;
					}
				}
			}
			
			foreach ($menuData as $k2=>$v2 )
			{
				foreach ($v2['children'] as $k3 =>$v3)
				{
					foreach ($menuDetail as $k4 =>$v4)
					{
						if($v3['fobjecttype'] == $v4['FObjectType']  && $v3['fobjectid'] == $v4['FObjectID'] )
						{
							$menuData[$k2]['children'][$k3]['child'][] = $v4;
						}
					}  
				}
			}
		}
		//是否在系统管理员组
		$groupSql = "select a.username,a.id from gz_user_group ug left join gz_admin a  on a.id= ug.userid where ug.groupid=1 and a.status =1 and a.username='{$loginname}'";
		$groupData = SqlServerUtil::execToSql($this->SqlServer, $groupSql,2);
		//系统管理组
		if($loginname == 'manager' || in_array($loginname, $groupData) ){
			showMsg(0,'成功',$menuData );
		}
		
		//用户是否属于哪个组 权限
		$group1 = "select a.username,a.id,ug.groupid,g.fname from gz_user_group ug 
			left join gz_admin a  on a.id= ug.userid left join gz_group g on g.id= ug.groupid  
			where a.username='{$loginname}' and a.status =1 order by ug.id desc ";
		$groupTemp = SqlServerUtil::execToSql($this->SqlServer, $group1 );
		//dd($groupTemp);
		if(empty($groupTemp)){
			showMsg(1,'该用户没有设置用户组权限',[]);
		}
		$groupid = join(',',array_column($groupTemp ,'groupid' )); //获取组 id
		
		//查询组列表
// 		$group2 = "select id,fname from gz_group where id !=1  ";
// 		$groupList = SqlServerUtil::execToSql($this->SqlServer, $group2);
		
		//查询用户--权限组列表
// 		$group3 = "select a.username,a.id,ug.groupid,g.fname fgroupname  from gz_user_group ug 
// 		left join gz_admin a  on a.id= ug.userid left join gz_group g on g.id= ug.groupid  
// 		where 1=1 and a.status =1 and  ug.groupid !=1  ";
// 		$usergroupList = SqlServerUtil::execToSql($this->SqlServer, $group3);
		
		//组权限 - gz_AccessControl_group
		$acsql="select ac.FObjectType,ac.FObjectID,ac.FUserID as FGroupid,ac.Fsqlist ,g.fname from gz_AccessControl_group ac 
		left join gz_group g on  g.id=ac.FUserID where ac.FUserID in ({$groupid})  ORDER BY ac.FObjectID ";
		$acList = SqlServerUtil::execToSql($this->SqlServer, $acsql);
		if(empty($acList)){
			showMsg(1,'该用户没有设置权限，请检查！',[]);
		}
		$arr =[];
		$ArrData=[];
		$result=[];
		$oneFObjectType  = join(',',array_keys(array_unset_tt($acList, 'FObjectType' )));
		
		$sql = "select FObjectType,FObjectID,FIndex,FAccessMask,FName from gz_ObjectAccessType where  FObjectType in ({$oneFObjectType})  ORDER BY  FObjectID ";
		$data = SqlServerUtil::execTosql($this->SqlServer,$sql);
// 		dd( $data , $acList , $menulistData,$menuTemp );
		///$acList, $data
		if($data && $acList){
			foreach ($data as $k =>$v){
				foreach ($acList as $k0=>$v0)
				{
					if( $v['FObjectType']== $v0['FObjectType']  && $v['FObjectID']== $v0['FObjectID'] ){
						$temp =[];
						$temp = explode(',',$v0['Fsqlist']);
						foreach ($temp as $k1=>$v1)
						{
							if($v1 == $v['FAccessMask'] ){
								$arr[$v['FObjectID']][] = $v;
							}
						}
						
					}
				}
			}
			//二级
			foreach ($menulistData as $k3=>$v3)
			{
				foreach ($arr as $k4=>&$v4)
				{
					if( $v3['fobjectid'] == $k4){
						$menulistData[$k3]['child'] =$v4;
						
					}
				}
				if(!isset($menulistData[$k3]['child'])){
					unset($menulistData[$k3]);
				}
				
			}
			
			//一级
			foreach ($menuTemp as $k4=>$v4)
			{
				foreach ($menulistData as $k5=>$v5)
				{
					if( $v4['fobjecttype'] == $v5['fobjecttype']){
						$menuTemp[$k4]['children'][] =$v5;
					}
				}
				if(!isset($menuTemp[$k4]['children'])){
					unset($menuTemp[$k4]);
				}
			}
			showMsg(0,'成功',array_merge([],$menuTemp));
		///if---END
		}else{
			showMsg(0,'成功',[] );
		}
	}
	
	/**
	* 聚一科技 ^_^
	* 修改密码
	* @date: 2020年11月4日
	* @author: lq
	* @version:App V2.0
	*/
	public function updatePass(Request $request){
		$username = $request->username;
		$password = $request->password;
		$newpassword = $request->newpassword;
		$type= $request->type ?$request->type : 1;
		//判断
		if(empty($username) || empty($password) || empty($newpassword)){
			showMsg(1,'参数错误，不能为空');
		}
		
		if($password == $newpassword){
			showMsg(1,'设置密码不能与原密码相同');
		}
		//判断密码
		if(!prefixPreg_11($newpassword) ){
			showMsg(1,'设置密码只能为英文数字');
		}
		if($type == 1){
			$pass = base64_encode($password);
			 
			$data = SqlServerUtil::execTosql($this->SqlServer,"select * from gz_admin where status =1 and username='{$username}' and password ='{$pass}'  ",2);
			if(empty($data)){
				showMsg(1,'用户名或密码错误');
			}
			$passNew = base64_encode($newpassword);
			$up = SqlServerUtil::sqlexecTosql($this->SqlServer, "update gz_admin set password='{$passNew}' where status =1 and username='{$username}'  ");
			
		}else{
			$data = SqlServerUtil::execTosql($this->SqlServer,"select * from t_userw where  FName='{$username}' and FSID ='{$password}'  ",2);
			if(empty($data)){
				showMsg(1,'用户名或密码错误');
			}
			$up = SqlServerUtil::sqlexecTosql($this->SqlServer, "update t_userw set FSID='{$newpassword}' where username='{$username}'  ");
		}
		//该用户是否有值
		if($up){
			showMsg(0,'成功');
		}else{
			showMsg(1,'失败');
		}
	}
	
	
	/**
	* 聚一科技 ^_^
	* @date: 2020年12月4日
	* @author: lq
	* @version:App V2.0
	*/
	public function setGongshi(Request $request){
		$data = SqlServerUtil::execTosql($this->SqlServer,"select FValue from gz_systemprofile where fcategory='IC' and fkey = 'FProductTimePreFld' ",2);
		$value = 1;
		if($data){
			if($data['FValue'] != 'FItemIDNumber')
			{
				$value = $data['FValue'];
			}
		}
		 
		showMsg(0,'成功',[$value]);
		
		
	}
	public function FZWDJList(Request $request){
		$data = SqlServerUtil::execTosql($this->SqlServer,"select fid ,fname from gz_Grade order by fname " );
		showMsg(0,'成功',$data);
	}
	
	//更新主控隐藏	
	public function updatezhukong(Request $request){
		//fobjhide
		$all = $request->all();
		$data = SqlServerUtil::sqlexecNo($this->SqlServer,"update gz_ObjectFunc set fobjhide ='{$all['fobjhide']}' where id ='{$all['id']}' " );
		if($data){
			showMsg(0,'修改成功');
		}
		showMsg(1,'修改失败');
	}
	
	//生成物料 number
	public function createNO(Request $request){
		$FRepKey = $request ->FRepKey;
		$return  = $this->getNumberNO($FRepKey);
		
		showMsg(0,'成功',$return);
	}
 
	//
	public function downFileUrl(Request $request){
		$FRepKey = $request ->FRepKey;
		//$jichuData = $this->getjichuziliao($request);
		$FRepPage  = $request->FRepPage??0 ; //这里0 -- 序时薄 ，1-单据
			
		$fname = SqlServerUtil::execTosql($this->SqlServer,"select fname from gz_ObjectType where FObjectID ='{$FRepKey}'  " ,2);
		$filename = '下载模板信息';
		if($fname){
// 			文件名
// 			$filename =$fname['fname'];
 			$filename = (string)$FRepKey;
		}
		$FRepFldData = SqlServerUtil::execTosql($this->SqlServer,"select frepfld,frepcap,frepmeg from gz_RepListTitle where FRepKey ='{$FRepKey}' and  FRepPage = '{$FRepPage}' and FRepHide =0  and FuploadFile =0 order by FRepIndex");
		if(empty($FRepFldData)){
			showMsg(400,'没有设置下载模板，请重试');
		}
		$tempfname = [];
		$tempfield = [];
		$FRepFld =[];
		$FRepFld = $FRepFldData;
		 
		foreach ($FRepFld as $k =>$v)
		{
			$tempfield[$k] = $v;
			
			$tempfield[$k]['frepfld'] = strtolower($v['frepfld']) ;
			$tempfname[] = $v['frepcap'];
		} 
	
		$data = SqlServerUtil::exec1($this->SqlServer,getReplaceSql(getfileSql($FRepKey)));
	
		$result = [];
		 
		if($data && count($data)>0){
			$data = arraykeyToLower($data);
			 
			foreach ( $data as $k =>$v)
			{
				foreach ( $tempfield as $k1 =>$v1)
				{
					if($v1['frepmeg'] == 1){
						//这里暂时 单位。品牌
							$result[$k][$v1['frepfld']] =  $v[$v1['frepfld']] ;
						if(1){
						//$result[$k][$v1['frepfld']] = getjichuData($jichuData , $v1['frepfld'],$v[$v1['frepfld']]) ;
						}
					}else{
						if($v[$v1['frepfld']] == '0'){
							$result[$k][$v1['frepfld']] = 0;
						}else{
							$result[$k][$v1['frepfld']] = $v[$v1['frepfld']];
						}
					}
				}
			}
		}
// 		dd($result);
		$cellData = array_merge([$tempfname],$result );
		$width = array('A'=>10,'B'=>10,'C'=>10,'D'=>10,'E'=>12,'F'=>12,'G'=>12,'H'=>25,'I'=>12,'J'=>12,'K'=>12,'L'=>12,'M'=>12,'N'=>12,'O'=>12);
		$stockname = $filename;
		Excel::create($stockname,function ($excel) use ($stockname,$cellData,$width){
			$excel->sheet($stockname, function ($sheet) use ($cellData,$width){
				$sheet->setWidth($width);
				$sheet->rows($cellData);
				$sheet->getStyle('A:AC')->getAlignment()->setWrapText(TRUE);
				$sheet->fromArray($cellData, null, 'A1', false, false)->setFontSize(12);
			});
				
		})->store('xlsx') ;
		$stockname = $stockname.'.xlsx';
		$pathToFile = storage_path('exports/'.$stockname);
		showMsg(0,'成功',$pathToFile);
	}
	
	
	public function downloadFile(Request $request){
		$FRepKey = $request ->FRepKey;
		$Fname = getMkName($FRepKey);
		return response()->download(realpath(base_path('storage')).'/exports/'.$FRepKey.'.xlsx',$Fname.'.xlsx');
		
	}
	
	//getDanHao
	public function getLiuShuiHao(Request $request){
		$FRepKey = $request ->FRepKey;
		$pathToFile = $this->getDanHao($FRepKey);
		showMsg(0,'成功',$pathToFile);
		
	}
	
	
	/**
	* 正式报价 业务流程 --确认  
	* @date: 2023年2月17日 上午11:04:16
	* @author: juyi
	*/
	public function ywQR(Request $request){
		$FRepKey = $request ->FRepKey;
		$db = columnBiao($FRepKey);
		
		$fisqr = $request ->fisqr??0;
		$getMkName =  '已确认' ; 
		$opername= $request->get('opername');
		
		$jsname ='技术'.$getMkName ;
		$cgname ='采购'.$getMkName ;
		$cwname ='财务'.$getMkName ;
		$data = $request ->get('data')  ;
		$time = getCurrentTime();
		$fisrqr = $request ->fisrqr??0 ; // 报错，再次 确认跳过
// 		dd($request ->all() );
		
		$FIDStr='';
		if ($request->has('fid') and $request->fid != '' and !empty($request->fid)) {
			$FID = $request->fid;
			$FIDStr=" and fid in ($FID) ";
		}
		$checkStr = "或没有审核";
		if($data){
		 
		if($fisqr == 1){
			//确认  --- 技术部
			//技术部 加账列表导入
			if($FRepKey == '14011'){
				foreach ( $data as $k=>$v){
					if($v['fisqrname']>0){
						showMsg(400,'已完成无法在操作 ！');
					}
					if($v['fisqr']>2){
						showMsg(400,'财务已确认 ，无法再操作 ！');
					}
					
				$sql="update {$db} set  fisqr = 1, fqrJS = '{$jsname}',opernameJS ='{$opername}',fcreattimeJS ='{$time}'  where 1=1 {$FIDStr}   ";
				//正式报价 -- 技术部
				$sql1 = " select * from gz_YBaseJS where 1=1 and fmodel = '{$v['fmodel']}' and fstatus = 1 " ;
				$resJS = SqlServerUtil::execToSql($this->SqlServer, $sql1 );
				if(empty($resJS)){
					showMsg(400,'当前业务流水号'.$v['fbillno'].'，技术中心没有这个机型 '.$checkStr.'，请检查。');
				}
				//ICER数据库信息 -- 技术：
				$resICERDBJS = []; 
				if($v['fegcmodel'] != '无'){
					$icerdbsql = " select v1.* from  gz_YjzICERDB v1 where  v1.fEGCModel = '{$v['fegcmodel']}' and v1.fstatus = 1  " ;
					$resICERDBJS = SqlServerUtil::execToSql($this->SqlServer, $icerdbsql,2 );
					if(empty($resICERDBJS)){
						showMsg(400, 'EGC型号: '.$v['fegcmodel'].' , 未审核，请检查。');
					}
				}
				
				//判断加账技术是否已审核
				$sqljs="select v1.fbrand,v1.fprodno, v1.fcode ,v1.fstatus,u1.fname  from gz_YjiazhangcbfMX v1
				inner join gz_YjiazhangcbfSet u1 on u1.fcode=v1.fcode
				where 1=1 and (u1.fcode <> 'JZW089' or u1.fcode <>'JZM079')  and v1.fprodno ='{$v['fmodel']}'  
				and ( charindex('技术',u1.fdanweibumen)>0 )";
				$resjs  = SqlServerUtil::execToSql($this->SqlServer, $sqljs );
				if($resjs){
					//判断是否有审核
					$one = array_unique(array_column($resjs,'fstatus'));
					if(in_array(0,$one)){
						showMsg(400,'加账技术机型：'.$v['fmodel'].'未审核,请检查');
					}
				}
				//加账 技术中心
				$sqljz = " select v1.fid as fscjzID ,v1.fbrand,v1.fprodno,v1.fywqty,v1.fcode,isnull(t1.fallamount,0) as foriamount,
				u1.fname,u1.fdanweibumen ,u1.fqty,u1.fzjqty,u1.fisgongshijs,
				u1.ffaxamount as fyzamount,'JS' as fbm  from gz_Yjiazhangcbf v1
				left join gz_YjiazhangcbfSet u1 on u1.fcode=v1.fcode 
				left join gz_YjiazhangcbfMX t1 on t1.fcode=v1.fcode and  t1.fprodno = v1.fprodno 
				where 1=1 and isnull(u1.fisgongshijs,0) <>6 and v1.fprodno ='{$v['fmodel']}' and v1.fbillno ='{$v['fbillno']}'
				 and ( charindex('技术',u1.fdanweibumen)>0 )  "; 
// 				echo $sqljz ; die;
				$resJZ  = SqlServerUtil::execToSql($this->SqlServer, $sqljz );
				if($fisrqr != 1){
					if(empty($resJZ)){
						showMsg(14009,'当前业务流水号:'.$v['fbillno'].'，技术中心没有加账清单金额导入。是否继续');
					}
				}
				//判断是否是甲醇机
				if( stripos( strtoupper($v['fmodel']) , 'LGIM' ) !== false){
					//甲醇机汇总
					$sql3 = " select * from gz_YjiachunHZ where 1=1 and fmodel = '{$v['fmodel']}' and fbillno ='{$v['fbillno']}' and fstatus =1  " ;
					$resRY = SqlServerUtil::execToSql($this->SqlServer, $sql3,2 );
					if(empty($resRY)){
						showMsg(400,'当前业务流水号:'.$v['fbillno'].'，甲醇汇总没有操作。'.$checkStr);
					}
					//甲醇汇总
					SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_YjiachunHZ_BAOJIA' , ['fjybjbillno'=> "'".$v['fbillno']."'" ],true);
					unset( $resRY['fid']); unset( $resRY['fcreatetime']);
					$resRY['fjybjbillno'] = $v['fbillno'];
					SqlServerUtil::sqlsrvCreate($this->SqlServer ,'gz_YjiachunHZ_BAOJIA' , $resRY);
				}
				
				//，燃油汇总
				$sql2 = " select * from gz_YranyouHZ where 1=1 and fmodel = '{$v['fmodel']}' and fbillno ='{$v['fbillno']}' and fstatus =1  " ;
				$resRY = SqlServerUtil::execToSql($this->SqlServer, $sql2,2 );
				if(empty($resRY)){
					showMsg(400,'当前业务流水号:'.$v['fbillno'].' ,燃油汇总没有操作。'.$checkStr);
				}
				//燃油汇总
				SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_YranyouHZ_BAOJIA' , ['fjybjbillno'=> "'".$v['fbillno']."'" ],true);
				unset( $resRY['fid']); unset( $resRY['fcreatetime']);
				$resRY['fjybjbillno'] = $v['fbillno'];
				SqlServerUtil::sqlsrvCreate($this->SqlServer ,'gz_YranyouHZ_BAOJIA' , $resRY);
				
				//参数设置
				$csSetData = $this->getSystemProfile(['FSetRGjiegouCJPrice','FSetRGjijiaCJPrice','FSetRGzhuangshiCJPrice','fsetZhuangShiRGprice','FSetFFAX','FSetChaiYouPrice','FSetQiGangPrice','FSetRanqiPrice']);
				//加账技术 生成 
				if($resJZ){
					foreach ($resJZ as $kjz =>$vjz)
					{
						if($fisrqr != 1){
							if($vjz['foriamount']<=0   && !in_array($vjz['fisgongshijs'],[3,4,5,6] )   ){
								showMsg(14009,'代码：'.$vjz['fcode'].',名称：'.$vjz['fname'].' 输入金额为 0 ，请检查',1);
							}
						}
						$resJZ[$kjz]['fjybjbillno'] = $v['fbillno'];
						$resJZ[$kjz]['fax']= $csSetData['fsetffax'] ;
						$resJZ[$kjz]['fzscjPrice']= $csSetData['fsetrgzhuangshicjprice'] ;
						$resJZ[$kjz]['fsxqty']= $v['fqty'] ;
						$resJZ[$kjz]['fbm']= 'JS' ;
						$resJZ[$kjz]['fywqty']= $vjz['fywqty'] ;
						$resJZ[$kjz]['fqty']= $vjz['fqty'] ;
						$resJZ[$kjz]['fzjqty']= $vjz['fzjqty'] ;
						$resJZ[$kjz]['fyzamount']= $vjz['fyzamount'] ; //设置参数值
						//技术中心 规则 5-20 
						$resJZ[$kjz]['foriamount']= getJZPriceJS( $vjz['foriamount'],$vjz['fisgongshijs'] , $csSetData  );
						$resJZ[$kjz]['fallAmount']= getJZguanzeJS($vjz['foriamount'],$vjz['fywqty'],$v['fqty'], $vjz['fisgongshijs']  ,$csSetData,(1+$csSetData['fsetffax']/100) ) ;
						unset($resJZ[$kjz]['fisgongshijs']); 
						
						//$resJZ[$kjz]['foriamount']= getJZPrice($vjz['foriamount'],$vjz['fbrand'],$vjz['fcode'] , $csSetData  ) ;//可以是修改后金额(技术导入金额)
						//$resJZ[$kjz]['fallAmount']= getJZguanze( $vjz['foriamount'] ,$vjz['fywqty'],$vjz['fbrand'] ,$vjz['fcode'] ,$v['fqty'] ,$csSetData,(1+$csSetData['fsetffax']/100) );
					}
					//加账技术 --报价 生成
					SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_Yjiazhangcbf_BAOJIA' , ['fjybjbillno'=> $v['fbillno'] ,'Fbm'=>'JS' ] );
					$in= SqlServerUtil::sqlsrvAllTosql($this->SqlServer ,'gz_Yjiazhangcbf_BAOJIA' , $resJZ);
				} 
				//技术生成
				if($resJS){
					foreach ($resJS as $kjs =>$vjs)
					{
						unset($resJS[$kjs]['fid']);
						unset($resJS[$kjs]['fcreatetime']);
						
						$resJS[$kjs]['fjybjbillno'] = $v['fbillno'];
						$resJS[$kjs]['fhanjieprice'] = $csSetData['fsetrgjiegoucjprice'];
						$resJS[$kjs]['fjijiaprice'] = $csSetData['fsetrgjijiacjprice'];
						$resJS[$kjs]['fzhuangshiprice'] = $csSetData['fsetrgzhuangshicjprice'];
						
					}
					//技术中心 --报价 生成
					SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_YBaseJS_BAOJIA' , ['fjybjbillno'=> "'".$v['fbillno']."'" ],true);
					$in= SqlServerUtil::sqlsrvAllTosql($this->SqlServer ,'gz_YBaseJS_BAOJIA' , $resJS);
				} 
				
			  }
			}
			
			//采购部 加账列表导入
			if($FRepKey == '14012'){
				$sql="update {$db} set  fisqr = 2, fqrCG = '{$cgname}' ,opernameCG ='{$opername}',fcreattimeCG = '{$time}'   where 1=1 {$FIDStr}   ";
				//参数设置
				$csSetData = $this->getSystemProfile(['FSetRGjiegouCJPrice','FSetRGjijiaCJPrice','FSetRGzhuangshiCJPrice','fsetZhuangShiRGprice','FSetRGzhuangshiCJPrice','FSetFFAX','FSetChaiYouPrice','FSetQiGangPrice','FSetRanqiPrice']);
				//采购部 --  正式报价 
				foreach ( $data as $k=>$v){
					if($v['fisqrname']>0){
						showMsg(400,'已完成无法在操作 ！');
					}
					if($v['fisqr']>2){
						showMsg(400,'财务已确认 ，无法再操作 ！');
					}
					//判断加账采购是否已审核
					$sqljs="select v1.fbrand,v1.fprodno, v1.fcode ,v1.fstatus,u1.fname  from gz_YjiazhangcbfMX v1
					inner join gz_YjiazhangcbfSet u1 on u1.fcode=v1.fcode
					where 1=1 and (u1.fcode <> 'JZW089' or u1.fcode <>'JZM079')  and v1.fprodno ='{$v['fmodel']}'  and ( charindex('采购',u1.fdanweibumen)>0 )";
					$resjs  = SqlServerUtil::execToSql($this->SqlServer, $sqljs );
					if($resjs){
						//判断是否有审核
						$one = array_unique(array_column($resjs,'fstatus'));
						if(in_array(0,$one)){
							showMsg(400,'加账采购机型：'.$v['fmodel'].'未审核,请检查');
						}
					}
					
					$sql1 = " select v1.* from gz_Ycaigoucbf v1   where 1=1 and v1.fprodno = '{$v['fmodel']}'  and fstatus =1 " ;
					$resCG = SqlServerUtil::execToSql($this->SqlServer, $sql1 );
					if(empty($resCG)){
						showMsg(400,'当前业务流水号:'.$v['fbillno'].'，采购成本没有数据'.$checkStr.'，请检查!');
					}
					
					//ICER数据库信息 -- 采购：
					$resICERDBCG = [];
					if($v['fegcmodel'] != '无'){
						$icerdbsql = " select v1.* from  gz_YjzICERDB v1	where  v1.fEGCModel = '{$v['fegcmodel']}' and v1.fstatuscg =1 " ;
						$resICERDBCG = SqlServerUtil::execToSql($this->SqlServer, $icerdbsql,2 );
						if(empty($resICERDBCG)){
							showMsg(400, 'ICER数据库信息,EGC型号: '.$v['fegcmodel'].' , 没有数据或未审核，请检查。');
						}
					}
					
					//判断加账采购是否已审核
					$sqljs="select v1.fbrand,v1.fprodno, v1.fcode ,v1.fstatus,u1.fname  from gz_YjiazhangcbfMX v1
					inner join gz_YjiazhangcbfSet u1 on u1.fcode=v1.fcode
					where 1=1 and (u1.fcode <> 'JZW089' or u1.fcode <>'JZM079')  and v1.fprodno ='{$v['fmodel']}'  
					and ( charindex('采购',u1.fdanweibumen)>0 )";
					$rescg  = SqlServerUtil::execToSql($this->SqlServer, $sqljs );
					if($rescg){
						//判断是否有审核
						$one = array_unique(array_column($rescg,'fstatus'));
						if(in_array(0,$one)){
							showMsg(400,'加账采购机型：'.$v['fmodel'].'未审核,请检查');
						}
					}
					
					////加账 采购  -- SCR 问题 
					$sqljz = " select v1.fid as fscjzID , v1.fbrand,v1.fprodno,v1.fywqty,v1.fcode,isnull(t1.fallamount,0) as foriamount,u1.fname,
					u1.fdanweibumen,u1.fqty,u1.fzjqty,u1.ffaxamount as fyzamount,u1.fisgongshijs, 'CG' as fbm  from gz_Yjiazhangcbf v1 
					left join gz_YjiazhangcbfSet u1 on u1.fcode=v1.fcode   
					left join gz_YjiazhangcbfMX t1 on t1.fcode=v1.fcode and t1.fprodno = v1.fprodno  
					where 1=1 and isnull(u1.fisgongshijs,0) <>6 and v1.fprodno ='{$v['fmodel']}' and v1.fbillno ='{$v['fbillno']}'  
					and ( charindex('采购',u1.fdanweibumen)>0 )" ;
					$resJZCG  = SqlServerUtil::execToSql($this->SqlServer, $sqljz );
// 					echo $sqljz;die;
					if($fisrqr != 1){
						if(empty($resJZCG)){
							showMsg(14009,'当前业务流水号:'.$v['fbillno'].'，采购没有加账清单金额导入。');
						}
					}
					//SCR 数据
					$SCRCG  = SqlServerUtil::execToSql($this->SqlServer, "SELECT fpowerkw,hpscrl,hpscrh,lpscrl,lpscrh  FROM gz_YSCRSet  " );
					
					//采购jiaz  生成
					if($resJZCG){
						foreach ($resJZCG as $kjz =>$vjz)
						{
							// 合同功率  fhtpower  ， HPSCR， LPSCR系统 高低硫
							if( stripos( $vjz['fname'] , 'PSCR' ) !== false ){
								if(substr(trim( $vjz['fname']),1,4) == 'PSCR') {
									$vjz['foriamount'] =  getSCRVal($SCRCG ,$v['fhtpower'] , $vjz['fcode'] );
								}
							}
							
							if($fisrqr != 1){
								if($vjz['foriamount']<=0){
									showMsg(14009, '代码：'.$vjz['fcode'].',名称：'.$vjz['fname'].' 输入金额为 0 ，请检查',1);
								}
							}
							
							$resJZCG[$kjz]['fjybjbillno'] = $v['fbillno'];
							$resJZCG[$kjz]['fax']= $csSetData['fsetffax'] ;
							$resJZCG[$kjz]['fzscjPrice']= $csSetData['fsetrgzhuangshicjprice'] ;
							$resJZCG[$kjz]['fsxqty']= $v['fqty'] ;
							$resJZCG[$kjz]['fbm']= 'CG' ;
							$resJZCG[$kjz]['fqty']= $vjz['fqty'] ;
							$resJZCG[$kjz]['fzjqty']= $vjz['fzjqty'] ;
							$resJZCG[$kjz]['fyzamount']= $vjz['fyzamount'] ;
							$resJZCG[$kjz]['fywqty']= $vjz['fywqty'] ;
							$resJZCG[$kjz]['foriamount']= $vjz['foriamount'] ;//修改金额   -- 这个 SCR
							// 加账采购 520 
							$resJZCG[$kjz]['fallAmount']=  getJZguanzeCG($vjz['foriamount'], $vjz['fywqty'], $vjz['fisgongshijs']   ) ;
							unset($resJZCG[$kjz]['fisgongshijs']);
							
// 							$resJZCG[$kjz]['fallAmount']=  getJZguanzeCG($vjz['foriamount'], $vjz['fywqty'], $vjz['fbrand'] ,$vjz['fcode'] ) ;
// 							$resJZCG[$kjz]['fallAmount']= getJZguanze( $vjz['foriamount'] ,$vjz['fywqty'], $vjz['fbrand'] ,$vjz['fcode'] ,$v['fqty'] ,$csSetData,(1+$csSetData['fsetffax']/100) );
						}
// 						dd($resJZCG);
						//加账技术 --报价 生成
						SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_Yjiazhangcbf_BAOJIA' , ['fjybjbillno'=> $v['fbillno'],'Fbm'=>'CG' ] );
						$in= SqlServerUtil::sqlsrvAllTosql($this->SqlServer ,'gz_Yjiazhangcbf_BAOJIA' , $resJZCG);
					} 
					//采购成本   
					if($resCG){
						foreach ($resCG as $cjs =>$cjs)
						{
							unset($resCG[$cjs]['fid']);
							unset($resCG[$cjs]['fcreatetime']);
							$resCG[$cjs]['fjybjbillno'] = $v['fbillno'];
						}
						
						SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_Ycaigoucbf_BAOJIA' , ['fjybjbillno'=> "'".$v['fbillno']."'" ],true);
						SqlServerUtil::sqlsrvAllTosql($this->SqlServer ,'gz_Ycaigoucbf_BAOJIA' , $resCG);
					}
				}	
			}
			
			//财务 部 加账列表导入  == 正式报价
			if($FRepKey == '14013'){
				//参数设置
				$csSetData = $this->getSystemProfile();
				//海外调试费   fsethaiwaitsf
				$hwtsf = empty($csSetData['fsethaiwaitsf'])? 0: $csSetData['fsethaiwaitsf'] ;
				
				// 判断其他部门 是否 已确认
				foreach ($data as $k =>$v)
				{
					if($v['fisqrname']>0){
						showMsg(400,'已完成无法在操作 ！');
					}
					if($v['fisqr'] <1  || empty($v['fqrjs']) ||  empty($v['fqrcg']) )
					{
						showMsg(400,'采购或技术部门还没有确认！');
					}
					$resZSQR  = SqlServerUtil::execToSql($this->SqlServer, "select fbillno from gz_YbaojiadanCB  where fbillno ='{$v['fbillno']}' and fstatus =1 ",2 );
					if($resZSQR){
						showMsg(400,$v['fbillno'].'正式报价已审核，无法再确认');
					}
					
					// 海外调试费 参数设置
					if($v['fishwtsf'] == '是' && $hwtsf == 0){
						showMsg(400, '流水号：'.$v['fbillno'].' ,业务需求海外调试费选择是，海外调试费参数设置为0，请检查');
					}
					if(!in_array($v['fchuanjishe'], ['CCS','ABS','LR','BV','DNV','NK' ] )){
						//判断质量部是否存在
						$zlbTmpData = SqlServerUtil::execToSql($this->SqlServer, "select fjybjbillno from gz_YchuanjianfQT where fjybjBillno ='{$v['fbillno']}' and FStatus = 1 ",2 );
						if(empty($zlbTmpData)  ){
							showMsg(400,'质量部-船检费其他, 未审核或没有引入流水号：'.$v['fbillno'].'，请检查.');
						}
					}
					
				}
				$sql="update {$db} set  fisqr = 3, fqrCW = '{$cwname}',opernameCW ='{$opername}',fcreattimeCW = '{$time}' where 1=1 {$FIDStr}   ";
				
				//专利费
				$ZlData = SqlServerUtil::execToSql($this->SqlServer, "select * from gz_Yzhuanlif where fstatus =1  " );
				if(empty($ZlData)){
					showMsg(400,'专利费没有数据或未审核，请检查');
				}
				//排放检测费
				$pfjjData = SqlServerUtil::execToSql($this->SqlServer, "select *  from gz_Ypfceshif where fstatus =1 " );
				if(empty($pfjjData)){
					showMsg(400,'排放检测费没有数据或未审核，请检查');
				}
				//图纸费
				$tzData = SqlServerUtil::execToSql($this->SqlServer, "select * from gz_Ytuzhif where fstatus =1 " );
				if(empty($tzData)){
					showMsg(400,'图纸费没有数据或未审核，请检查');
				}
				
				//船社级 参数
				$csjData = SqlServerUtil::execToSql($this->SqlServer, "select * from gz_YchuanjianfSet order by fsort asc  " );
				//正式数据生成
				foreach ($data as $k =>&$v)
				{
// 					//技术部门 -- 查询
					 $jsData = SqlServerUtil::execToSql($this->SqlServer, "select * from gz_YBaseJS_BAOJIA where fmodel ='{$v['fmodel']}' and fjybjBillno ='{$v['fbillno']}' ",2 );
					 if(empty($jsData)  ){
					 	showMsg(400,'技术部门未确认，请检查');
					 }
					//燃油汇总 -- 查询
					 $ryData = SqlServerUtil::execToSql($this->SqlServer, "select * from gz_YranyouHZ_BAOJIA where fmodel ='{$v['fmodel']}' and fjybjBillno ='{$v['fbillno']}' ",2 );
					 
					 //加账SCR/ICER管理
					 //判断是否是甲醇机
					 if( stripos( strtoupper($v['fmodel']) , 'LGIM' ) !== false)    {
					 	$JCData = SqlServerUtil::execToSql($this->SqlServer, "select * from  gz_YjzJiaChunQT where fbillno ='{$v['fbillno']}' ",2 );
					 	if(empty($JCData) ){
					 		showMsg(400,'甲醇机,当前流水号：'.$v['fbillno'].'，请在加账SCR/ICER管理进行数据确认！');
					 	}
					 }else{
					 	$SCRData = SqlServerUtil::execToSql($this->SqlServer, "select * from  gz_YjzSCREGRHZ where fmodel ='{$v['fmodel']}' and fbillno ='{$v['fbillno']}' ",2 );
					 	if(empty($SCRData) ){
					 		showMsg(400,'当前流水号：'.$v['fbillno'].'，请在加账SCR/ICER管理进行数据确认！');
					 	}
					 }
					 
					 $v['fbrand'] = $jsData['fbrand'];
					 
					 //ICER数据库信息 （技术采购 ）   -- 财务
					 if($v['fegcmodel'] != '无'){
					 	$ICERTemp = $this->getICERQR($v['fegcmodel'],'27010',$v['fbillno']);
					 	if($ICERTemp){
					 		SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_YjzICERDB_BAOJIA' , ['fjybjbillno'=> "'".$v['fbillno']."'" ],true);
					 		SqlServerUtil::sqlsrvCreate($this->SqlServer ,'gz_YjzICERDB_BAOJIA' , $ICERTemp);
					 	}
					 }
					//图纸费  getTZValueQR  == 1
				    $tzTemp = $this->getTZValueQR($tzData  ,$v['fmodel'],$jsData['fbrand'],$v['fbillno']);
// 				    dd($tzTemp, $tzData  ,$v['fmodel'],$jsData['fbrand'],$v['fbillno']);
					if($tzTemp){
						SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_Ytuzhif_BAOJIA' , ['fjybjbillno'=> "'".$v['fbillno']."'" ],true);
						SqlServerUtil::sqlsrvCreate($this->SqlServer ,'gz_Ytuzhif_BAOJIA' , $tzTemp);
					}
					//焊接车间(辅材) == 1
					$hjcjTemp = $this->getjixingQR($v['fmodel'],' 26008',$v['fbillno']);
					if(empty($hjcjTemp)){
						showMsg(400,  '焊接车间(辅材) ,机型'.$v['fmodel'].'数据为空'.$checkStr.'，请检查');
					}
					if($hjcjTemp){
						SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_Yfucaicbf_BAOJIA' , ['fjybjbillno'=> "'".$v['fbillno']."'" ],true);
						SqlServerUtil::sqlsrvCreate($this->SqlServer ,'gz_Yfucaicbf_BAOJIA' , $hjcjTemp);
					}
					//机加工车间(辅材) == 1
					$jjgcjTemp = $this->getjixingQR($v['fmodel'],'28006',$v['fbillno']);
					if(empty($jjgcjTemp)){
						showMsg(400,  '机加工车间(辅材) ,机型'.$v['fmodel'].'数据为空'.$checkStr.'，请检查');
					}
					if($jjgcjTemp){
						SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_Yfucaicbfjijia_BAOJIA' , ['fjybjbillno'=> "'".$v['fbillno']."'" ],true);
						SqlServerUtil::sqlsrvCreate($this->SqlServer ,'gz_Yfucaicbfjijia_BAOJIA' , $jjgcjTemp);
					}
					//装试车间(辅材) == 1
					$zscjTemp = $this->getjixingQR($v['fmodel'],'28007',$v['fbillno']);
					if(empty($zscjTemp)){
						showMsg(400,  '装试车间(辅材) ,机型'.$v['fmodel'].'数据为空'.$checkStr.'，请检查');
					}
					if($zscjTemp){
						SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_Yfucaicbfzshi_BAOJIA' , ['fjybjbillno'=> "'".$v['fbillno']."'" ],true);
						SqlServerUtil::sqlsrvCreate($this->SqlServer ,'gz_Yfucaicbfzshi_BAOJIA' , $zscjTemp);
					}
					
					// 质量成本 26013  == 1
					$zhiliangTemp = $this->getjixingQR($v['fmodel'],'26013',$v['fbillno']);
					if(empty($zhiliangTemp)){
						showMsg(400, '质量成本 ,机型'.$v['fmodel'].'数据为空'.$checkStr.'，请检查');
					}
					if($zhiliangTemp){
						SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_Yzhiliangcb_BAOJIA' , ['fjybjbillno'=> "'".$v['fbillno']."'" ],true);
						SqlServerUtil::sqlsrvCreate($this->SqlServer ,'gz_Yzhiliangcb_BAOJIA' , $zhiliangTemp);
					}
					
					//售后成本	 26012 == 1
					$shcbTemp = $this->getjixingQR($v['fmodel'],'26012',$v['fbillno']);
					if(empty($shcbTemp)){
						showMsg(400,  '售后成本 ,机型'.$v['fmodel'].'数据为空'.$checkStr.'，请检查');
					}
					if($shcbTemp){
						SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_Yshtswhcb_BAOJIA' , ['fjybjbillno'=> "'".$v['fbillno']."'" ],true);
						SqlServerUtil::sqlsrvCreate($this->SqlServer ,'gz_Yshtswhcb_BAOJIA' , $shcbTemp);
					}
					//水电
					$sdTemp = $this->getjixingQR($v['fmodel'],'26011',$v['fbillno']);
					if(empty($sdTemp)){
						showMsg(400,'水电费 ,机型'.$v['fmodel'].'数据为空'.$checkStr.'，请检查');
					}
					if($sdTemp){
						SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_Yshuidianf_BAOJIA' , ['fjybjbillno'=> "'".$v['fbillno']."'" ],true);
						SqlServerUtil::sqlsrvCreate($this->SqlServer ,'gz_Yshuidianf_BAOJIA' , $sdTemp);
					}
				
					//（（燃油汇总(（机型数量* 参数设置单价）+(生效台数-1）*（燃油汇总（机型数量* 参数设置单价）））) /生效台数
// 					$ry = getRanYouHZ($ryData, $v['fisryrq']);
					$ryData1 = arraykeyToLower($ryData) ;
					$ry = getyouqifHZ($ryData1 ) ;
// 					dd(  $ry );
					//油气费  == 涉及到 参数设置问题
					$yqTemp = [
							'fjybjbillno' => $v['fbillno'] ,
							'fbrand'=>$v['fbrand'],
							'fprodno'=>$v['fmodel'],
							'funit' =>'',
							'FdieselOilQty'=> $ry['ranyou'],// 燃油kg
							'fprice'=>$csSetData['fsetchaiyouprice'],
							'fCylinderoil'=> $ry['qigang'], // 气缸油kg
							'fCylinderoilPrice' =>$csSetData['fsetqigangprice'],
							'fgasQty'=> $ry['ranqi'], //燃气kg 
							'fsxqty'=>$v['fqty'],
							'fgasPrice'=>$csSetData['fsetranqiprice'],
							
							'fnoranyou'=> $ry['noranyou'],// 燃油kg
							'fnoqigang'=> $ry['noqigang'], // 气缸油kg
							'fnoranqi'=> $ry['noranqi'], //燃气kg
							//燃气kg	fGas , 然油kg	 fdieselOil ， 气缸油kg	fCylinderoil
							'fAllamount'=> round((( $ry['ranyou'] *$csSetData['fsetchaiyouprice'] +$ry['qigang']*$csSetData['fsetqigangprice'] 
									+ $ry['ranqi']*$csSetData['fsetranqiprice'] )+($v['fqty']-1)*( $ry['noranyou'] *$csSetData['fsetchaiyouprice'] +$ry['noqigang']*$csSetData['fsetqigangprice']
											+ $ry['noranqi']*$csSetData['fsetranqiprice'] )   )/$v['fqty'] ,2),
					];
					if($yqTemp){
						SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_Yyouqif_BAOJIA' , ['fjybjbillno'=> "'".$v['fbillno']."'" ],true);
						SqlServerUtil::sqlsrvCreate($this->SqlServer ,'gz_Yyouqif_BAOJIA' , $yqTemp);
					}
					
					//排放测试费   getPfjjValueQR
					$pfcsTemp  = getPfjjValueQR($pfjjData ,$v['fmodel'],$v['fbillno']);
					if($pfcsTemp){
						SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_Ypfceshif_BAOJIA' , ['fjybjbillno'=> "'".$v['fbillno']."'" ],true);
						SqlServerUtil::sqlsrvCreate($this->SqlServer ,'gz_Ypfceshif_BAOJIA' , $pfcsTemp);
					}
					
					//专利确认   getZLValueQR
					$zlTemp  = getZLValueQR($ZlData ,$v['fmodel'],$v['fbrand'],$v['fbillno'],$csSetData['fsetzhaunlifeibl'], $csSetData['fsetzhaunlifeiblman'],$csSetData['fsetffax'] );
					if($zlTemp){
						SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_Yzhuanlif_BAOJIA' , ['fjybjbillno'=> "'".$v['fbillno']."'" ],true);
						SqlServerUtil::sqlsrvCreate($this->SqlServer ,'gz_Yzhuanlif_BAOJIA' , $zlTemp);
					}
					
					//判断加账财务是否已审核
					$sqljs="select v1.fbrand,v1.fprodno, v1.fcode ,v1.fstatus,u1.fname  from gz_YjiazhangcbfMX v1
					inner join gz_YjiazhangcbfSet u1 on u1.fcode=v1.fcode
					where 1=1 and v1.fprodno ='{$v['fmodel']}' 
					 and ( charindex('其他',u1.fdanweibumen)>0 or charindex('生产',u1.fdanweibumen)>0  or charindex('质量',u1.fdanweibumen)>0  or charindex('售后',u1.fdanweibumen)>0 ) ";
					$resjs  = SqlServerUtil::execToSql($this->SqlServer, $sqljs );
					if($resjs){
						//判断是否有审核
						$one = array_unique(array_column($resjs,'fstatus'));
						if(in_array(0,$one)){
							showMsg(400,'加账其他 机型：'.$v['fmodel'].'未审核,请检查');
						}
					}
					
					//加账 其他部门
					$sqljzqt = " select v1.fid as fscjzID ,v1.fbrand,v1.fprodno,v1.fywqty,v1.fcode,isnull(t1.fallamount,0) as foriamount,u1.fname,
					u1.fdanweibumen,u1.fqty,u1.fzjqty,u1.ffaxamount as fyzamount  ,'QT' as fbm  
					from gz_Yjiazhangcbf v1 
					left join gz_YjiazhangcbfSet u1 on u1.fcode=v1.fcode  
					left join gz_YjiazhangcbfMX t1 on t1.fcode=v1.fcode  and  t1.fprodno = v1.fprodno
					where 1=1 and v1.fprodno ='{$v['fmodel']}'  and v1.fbillno ='{$v['fbillno']}' and ( charindex('其他',u1.fdanweibumen)>0 or charindex('生产',u1.fdanweibumen)>0  or charindex('质量',u1.fdanweibumen)>0  or charindex('售后',u1.fdanweibumen)>0 ) " ;
					$resJZQT  = SqlServerUtil::execToSql($this->SqlServer, $sqljzqt );
					// fisrqr
					if($fisrqr != 1){
						if(empty($resJZQT)){
								showMsg(14009,'当前业务流水号'.$v['fbillno'].'，其他部门没有加账清单导入。');
						}
					}
					//加账其他部门 生成
					if($resJZQT){
						foreach ($resJZQT as $kjz =>$vjz)
						{
							if($fisrqr != 1){
								if($vjz['foriamount']<=0){
									showMsg(14009,'代码：'.$vjz['fcode'].'，名称：'.$vjz['fname'].' 输入金额为 0 ，请检查',1);
								}
							}
							
							$resJZQT[$kjz]['fjybjbillno'] = $v['fbillno'];
							$resJZQT[$kjz]['fax']= $csSetData['fsetffax'] ;
							$resJZQT[$kjz]['fzscjPrice']= $csSetData['fsetrgzhuangshicjprice'] ;
							$resJZQT[$kjz]['fsxqty']= $v['fqty'] ;
							$resJZQT[$kjz]['fbm']= 'QT' ;
							
							$resJZQT[$kjz]['fzjqty']= $vjz['fzjqty'] ;
							$resJZQT[$kjz]['fyzamount']= $vjz['fyzamount'] ;
							$resJZQT[$kjz]['fywqty']= $vjz['fywqty'] ;
							$resJZQT[$kjz]['fyzamount']= $vjz['fyzamount'] ;
							$resJZQT[$kjz]['foriamount']= $vjz['foriamount'] ; //修改金额
							
							$resJZQT[$kjz]['fallAmount']= round( $vjz['foriamount'] *$vjz['fywqty'] ,2 ); 
							
						}
						//加账技术 --报价 生成
						SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_Yjiazhangcbf_BAOJIA' , ['fjybjbillno'=> $v['fbillno'],'Fbm'=>'QT' ]);
						$in= SqlServerUtil::sqlsrvAllTosql($this->SqlServer ,'gz_Yjiazhangcbf_BAOJIA' , $resJZQT);
					}
					//这里 船社级   (合同功率*整机检验费+确定部分)+(母型机NOX排放*1+子型机NOX排放*(生效台数-1))/生效台数
					//CCS:(合同功率*整机检验费+确定部分)+（母型机NOX排放*1+子型机NOX排放*（生效台数-1））/生效台数
					//ABS汇率问题 ，  其他  (整机检验费*汇率 +确定部分)+（母型机NOX排放*1+子型机NOX排放*（生效台数-1））/生效台数
					$cjsTemp =  []; 
					
					if( in_array($v['fchuanjishe'], ['CCS','ABS','LR','BV','DNV','NK' ] )){
						if($v['fchuanjishe'] !== 'DNV'){
							$cjsTemp =  getCSJData($csjData ,$v['fhtpower'] ,$v['fqty'] ,$v['fchuanjishe'],$v['fmodel']);
							$cjfallamount = 0 ;
							$fsetcjsbvamount = 0 ;
							if(!empty($cjsTemp)){
								// fsjcjfAmount  -- 收费标准 
								if($v['fchuanjishe'] == 'CCS'){
									$cjfallamount =round((( $v['fhtpower']*$cjsTemp['fsjcjfAmount']+ $cjsTemp['fqueding']) + ($cjsTemp['fnoxpfMXRMB']+$cjsTemp['fnoxpfZXRMB']*($v['fqty']-1) )/$v['fqty']),2)   ;
								}elseif($v['fchuanjishe'] == 'ABS'){
									//考虑汇率
									$cjfallamount =	round((( $cjsTemp['fsjcjfAmount']*$cjsTemp['fhuilv']+ $cjsTemp['fqueding']) + ($cjsTemp['fnoxpfMXRMB']+$cjsTemp['fnoxpfZXRMB']*($v['fqty']-1) )/$v['fqty']),2);
								}elseif($v['fchuanjishe'] == 'LR'){
									///双燃料机
									$abs =1  ;
									if(stripos( strtoupper($v['fmodel']) , 'DF' ) !== false ||  stripos( strtoupper($v['fmodel']) , 'SCR' ) !== false || stripos( strtoupper($v['fmodel']) , 'EGR' ) !== false || stripos( strtoupper($v['fmodel']) , 'LGIM' ) !== false){
										//双燃料机
										$abs =1.3 ;
									} 
									$cjfallamount =	round((( $cjsTemp['fsjcjfAmount']*$abs + $cjsTemp['fqueding']) + ($cjsTemp['fnoxpfMXRMB']+$cjsTemp['fnoxpfZXRMB']*($v['fqty']-1) )/$v['fqty']),2);
								}elseif($v['fchuanjishe'] == 'BV'){
									$fsetcjsbvamount = 0 ;
									if(stripos( strtoupper($v['fmodel']) , 'DF' ) !== false ||  stripos( strtoupper($v['fmodel']) , 'SCR' ) !== false || stripos( strtoupper($v['fmodel']) , 'EGR' ) !== false || stripos( strtoupper($v['fmodel']) , 'LGIM' ) !== false){
										//双燃料机
										$fsetcjsbvamount = $csSetData['fsetcjsbvamount'] ;
									}
									$cjfallamount =	round((( $cjsTemp['fsjcjfAmount']+ $cjsTemp['fqueding']+ $fsetcjsbvamount) + ($cjsTemp['fnoxpfMXRMB']+$cjsTemp['fnoxpfZXRMB']*($v['fqty']-1) )/$v['fqty']),2);
								}else{
									// NK  
									$cjfallamount =	round((( $cjsTemp['fsjcjfAmount'] + $cjsTemp['fqueding']) + ($cjsTemp['fnoxpfMXRMB']+$cjsTemp['fnoxpfZXRMB']*($v['fqty']-1) )/$v['fqty']),2);
								}
	// 							dd($v , $cjsTemp ,$cjfallamount );
								$cjsArr =[
										'fjybjbillno' => $v['fbillno'] ,
										'ftype' =>$cjsTemp['ftype'],
										'fzjjianyanf'=> $cjsTemp['fsjcjfAmount'],
										'fzhengshuf'=> $cjsTemp['fzhengshufRMB'],
										'flutuf'=> $cjsTemp['flutufRMB'],
										'fjizuojijiaf'=> $cjsTemp['fscjjRMB'],
										
										'fquedingbf'=> $cjsTemp['fqueding'],
										'fpaifangmuxing'=>  $cjsTemp['fnoxpfMXRMB'],
										'fpaifangzixing'=> $cjsTemp['fnoxpfZXRMB'],
										'FExchangeRate'=> $cjsTemp['fhuilv'],
										
										'fallamount'=> $cjfallamount,
										'fbrand'=> $v['fbrand'],
										'fmodel'=>$v['fmodel'],
										'fpower'=>$v['fhtpower'],
										'fsetcjsbvamount'=>$fsetcjsbvamount,
										
								];
							}else{
								$cjsArr =[
										'fjybjbillno' => $v['fbillno'] ,
										'fbrand'=> $v['fbrand'],
										'fmodel'=>$v['fmodel'],
										'fpower'=>$v['fhtpower'],
										'ftype' =>$v['fchuanjishe'],
										
										'fzjjianyanf'=> 0,
										'fzhengshuf'=>0,
										'flutuf'=>0,
										
										'fquedingbf'=> 0,
										'fpaifangmuxing'=>  0,
										'fpaifangzixing'=> 0,
										'FExchangeRate'=> 0,
										'fallamount'=> $cjfallamount,
										
								];
							}
							SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_Ychuanjianfgd' , ['fjybjbillno'=> "'".$v['fbillno']."'" ],true);
							SqlServerUtil::sqlsrvCreate($this->SqlServer ,'gz_Ychuanjianfgd' , $cjsArr);
							
						}else{
							$DNVTmep = $this->getChuanjianQR($v['fmodel'],'25005',$v['fbillno'] );
							if($DNVTmep){
								SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_YchuanjianfDNV_BAOJIA' , ['fjybjbillno'=> "'".$v['fbillno']."'" ],true);
								SqlServerUtil::sqlsrvCreate($this->SqlServer ,'gz_YchuanjianfDNV_BAOJIA' , $DNVTmep);
							}
						}
					}else{
 						//其他船级社
						
					}
						
					//生产部机型  委外费用	工装-整体发运	工装-分体发运   刀具
					$prodTemp = $this->getProdQR($v['fmodel'],'14010',$v['fbillno'],$csSetData  );
					if(empty($prodTemp)){
						showMsg(400, '生产部机型 ,机型'.$v['fmodel'].'数据为空'.$checkStr.'，请检查');
					}
					if($prodTemp){
						SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_YBaseProduce_BAOJIA' , ['fjybjbillno'=> "'".$v['fbillno']."'" ],true);
						SqlServerUtil::sqlsrvCreate($this->SqlServer ,'gz_YBaseProduce_BAOJIA' , $prodTemp);
					}
					//折旧
					$zjTemp = $this->getzhejiuQR($v['fbillno'] );
					if(empty($zjTemp)){
						showMsg(400, ' 折旧费 本年度没有数据 ，'.$checkStr.'，请检查');
					}
					if($zjTemp){
						SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_Yzhejiuf_BAOJIA' , ['fjybjbillno'=> "'".$v['fbillno']."'" ],true);
						SqlServerUtil::sqlsrvCreate($this->SqlServer ,'gz_Yzhejiuf_BAOJIA' , $zjTemp);
					}
				}
				//折旧
// 				echo $sql;die;
			}
			
			
			//正式加账管理  确认  ---加账  技术部
			if($FRepKey == '34002'){
				//参数设置
				$csSetData = $this->getSystemProfile();
				$sql="update {$db} set  fisqr = 1, fqrJS = '{$jsname}',opernameJS ='{$opername}', fcreattimeJS='{$time}'  where 1=1 {$FIDStr}   ";
				foreach ($data as $k =>&$v)
				{
					if($v['fisqrname']>0){
						showMsg(400,'已完成无法在操作 ！');
					}
					if($v['fisqr']>2){
						showMsg(400,' 财务已确认 ，无法再操作 ！');
					}
					//判断加账技术是否已审核
					$sqljs="select v1.fbrand,v1.fprodno, v1.fcode ,v1.fstatus,u1.fname  from gz_YjiazhangcbfMX v1
					inner join gz_YjiazhangcbfSet u1 on u1.fcode=v1.fcode
					where 1=1 and (u1.fcode <> 'JZW089' or u1.fcode <>'JZM079')  and v1.fprodno ='{$v['fmodel']}'  and ( charindex('技术',u1.fdanweibumen)>0 )";
					$rescg  = SqlServerUtil::execToSql($this->SqlServer, $sqljs );
					if($rescg){
						//判断是否有审核
						$one = array_unique(array_column($rescg,'fstatus'));
						if(in_array(0,$one)){
							showMsg(400,'加账技术 机型：'.$v['fmodel'].'未审核,请检查');
						}
					}
					
					////加账 技术
					$sqljz = " select v1.fbrand,v1.fprodno,v1.fywqty,v1.fcode,isnull(t1.fallamount,0) as foriamount,
					u1.fname,u1.fdanweibumen,u1.fqty,u1.fzjqty,u1.ffaxamount as fyzamount,u1.fisgongshijs, 'JS' as fbm  
					from gz_Yjiazhangcbf_HXJZ  v1
					left join gz_YjiazhangcbfSet u1 on u1.fcode=v1.fcode  
					left join gz_YjiazhangcbfMX t1 on t1.fcode=v1.fcode and t1.fprodno = v1.fprodno  
					where 1=1 and isnull(u1.fisgongshijs,0) <>6  and v1.fbillnoentry ='{$v['fbillnoentry']}'
					 and ( charindex('技术',u1.fdanweibumen)>0 ) " ;
// 					echo $sqljz;die;
					$resJZCG  = SqlServerUtil::execToSql($this->SqlServer, $sqljz );
					if(empty($resJZCG)){
						if($fisrqr != 1){
							showMsg(14009,'当前业务流水号：'.$v['fbillnoentry'].'，技术中心没有加账清单金额导入。');
						}
					}
					//技术jiaz  生成
					if($resJZCG){
						foreach ($resJZCG as $kjz =>$vjz)
						{
							if($fisrqr != 1){
								if($vjz['foriamount']<=0 && !in_array($vjz['fisgongshijs'],[3,4,5,6] )){
									showMsg(14009,'代码：'.$vjz['fcode'].'，名称：'.$vjz['fname'].' 输入金额为 0 ，请检查',1);
								}
							}
							$resJZCG[$kjz]['fjybjbillno'] = $v['fbillno'];
							$resJZCG[$kjz]['fbillnoentry'] = $v['fbillnoentry'];
							$resJZCG[$kjz]['fax']= $csSetData['fsetffax'] ;
							$resJZCG[$kjz]['fzscjPrice']= $csSetData['fsetrgzhuangshicjprice'] ;
							$resJZCG[$kjz]['fsxqty']= $v['fqty'] ;
							$resJZCG[$kjz]['fbm']= 'JS' ;
							$resJZCG[$kjz]['fqty']= $vjz['fqty'] ;
							$resJZCG[$kjz]['fzjqty']= $vjz['fzjqty'] ;
							$resJZCG[$kjz]['fyzamount']= $vjz['fyzamount'] ;
							$resJZCG[$kjz]['fywqty']= $vjz['fywqty'] ;
							//正式加账管理  ---加账  技术部
							$resJZCG[$kjz]['foriamount']= getJZPriceJS($vjz['foriamount'], $vjz['fisgongshijs'] ,$csSetData);//修改金额
							$resJZCG[$kjz]['fallAmount']= getJZguanzeJS( $vjz['foriamount'] ,$vjz['fywqty'],$v['fqty'],$vjz['fisgongshijs'] ,$csSetData,(1+$csSetData['fsetffax']/100) );
							unset($resJZCG[$kjz]['fisgongshijs']);
							
// 							$resJZCG[$kjz]['foriamount']= getJZPrice($vjz['foriamount'], $vjz['fbrand'] ,$vjz['fcode'] ,$csSetData);//修改金额
// 							$resJZCG[$kjz]['fallAmount']= getJZguanze( $vjz['foriamount'] ,$vjz['fywqty'], $vjz['fbrand'] ,$vjz['fcode'] ,$v['fqty'] ,$csSetData,(1+$csSetData['fsetffax']/100) );
						}
						//加账技术 --报价 生成
						SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_Yjiazhangcbf_HXJZ_BAOJIA' , ['fbillnoentry'=> $v['fbillnoentry'],'Fbm'=>'JS' ] );
						$in= SqlServerUtil::sqlsrvAllTosql($this->SqlServer ,'gz_Yjiazhangcbf_HXJZ_BAOJIA' , $resJZCG);
					}
				}
			}
			
			//正式加账管理   确认  ---加账  采购部 
			if($FRepKey == '34003'){
				//参数设置
				$csSetData = $this->getSystemProfile();
				//采购部
				$sql="update {$db} set  fisqr = 2, fqrCG = '{$cgname}' ,opernameCG ='{$opername}', fcreattimeCG='{$time}'  where 1=1 {$FIDStr}   ";
				foreach ($data as $k =>&$v)
				{
					if($v['fisqrname']>0){
						showMsg(400,'已完成无法在操作 ！');
					}
					if($v['fisqr']>2){
						showMsg(400,'财务已确认 ，无法再操作 ！');
					}
					
					//判断加账采购是否已审核
					$sqljs="select v1.fbrand,v1.fprodno, v1.fcode ,v1.fstatus,u1.fname  from gz_YjiazhangcbfMX v1
					inner join gz_YjiazhangcbfSet u1 on u1.fcode=v1.fcode
					where 1=1 and v1.fprodno ='{$v['fmodel']}'  and ( charindex('采购',u1.fdanweibumen)>0 )";
					$rescg  = SqlServerUtil::execToSql($this->SqlServer, $sqljs );
					if($rescg){
						//判断是否有审核
						$one = array_unique(array_column($rescg,'fstatus'));
						if(in_array(0,$one)){
							showMsg(400,'加账采购 机型：'.$v['fmodel'].'未审核,请检查');
						}
					}	
					
					////加账 采购
					$sqljz = " select v1.fbrand,v1.fprodno,v1.fywqty,v1.fcode,isnull(t1.fallamount,0) as foriamount,u1.fname,u1.fdanweibumen,
					u1.fqty,u1.fzjqty,u1.ffaxamount as fyzamount,u1.fisgongshijs , 'CG' as fbm  from gz_Yjiazhangcbf_HXJZ  v1
					left join gz_YjiazhangcbfSet u1 on u1.fcode=v1.fcode  
					left join gz_YjiazhangcbfMX t1 on t1.fcode=v1.fcode and t1.fprodno = v1.fprodno  
					where 1=1 and isnull(u1.fisgongshijs,0) <>6  and v1.fbillnoentry ='{$v['fbillnoentry']}'  and ( charindex('采购',u1.fdanweibumen)>0 ) " ;
// 					echo $sqljz;die;
					//( charindex('采购',u1.fdanweibumen)>0 )  // AND t1.fbm= 'CG'
					$resJZCG  = SqlServerUtil::execToSql($this->SqlServer, $sqljz );
					if(empty($resJZCG)){
						if($fisrqr != 1){
							showMsg(14009,'当前业务流水号：'.$v['fbillnoentry'].'，采购没有加账清单金额导入。');
						}
						
					}
					//SCR 数据
					$SCRCG  = SqlServerUtil::execToSql($this->SqlServer, "SELECT fpowerkw,hpscrl,hpscrh,lpscrl,lpscrh  FROM gz_YSCRSet  " );
					//采购jiaz  生成
					if($resJZCG){
						foreach ($resJZCG as $kjz => $vjz)
						{
							// 合同功率  fhtpower  ， HPSCR， LPSCR系统 高低硫
							if( stripos( $vjz['fname'] , 'PSCR' ) !== false){
								if(substr(trim( $vjz['fname']),1,4) == 'PSCR') {
									$vjz['foriamount'] =  getSCRVal($SCRCG ,$v['fhtpower'] , $vjz['fcode'] );
								}
							}
							
							if($fisrqr != 1){
								if($vjz['foriamount']<=0){
									showMsg(14009,'代码：'.$vjz['fcode'].'，名称：'.$vjz['fname'].' 输入金额为 0 ，请检查',1);
								}
							}
							
							$resJZCG[$kjz]['fjybjbillno'] = $v['fbillno'];
							$resJZCG[$kjz]['fbillnoentry'] = $v['fbillnoentry'];
							$resJZCG[$kjz]['fax']= $csSetData['fsetffax'] ;
							$resJZCG[$kjz]['fzscjPrice']= $csSetData['fsetrgzhuangshicjprice'] ;
							$resJZCG[$kjz]['fsxqty']= $v['fqty'] ;
							$resJZCG[$kjz]['fbm']= 'CG' ;
							$resJZCG[$kjz]['fqty']= $vjz['fqty'] ;
							$resJZCG[$kjz]['fzjqty']= $vjz['fzjqty'] ;
							$resJZCG[$kjz]['fyzamount']= $vjz['fyzamount'] ;
							$resJZCG[$kjz]['fywqty']= $vjz['fywqty'] ;
							$resJZCG[$kjz]['foriamount']= $vjz['foriamount'] ;//修改金额
							$resJZCG[$kjz]['fallAmount']= getJZguanzeCG( $vjz['foriamount'] ,$vjz['fywqty'], $vjz['fisgongshijs']  );
							unset($resJZCG[$kjz]['fisgongshijs']);
							// $resJZCG[$kjz]['fallAmount']= getJZguanzeCG( $vjz['foriamount'] ,$vjz['fywqty'], $vjz['fbrand'] ,$vjz['fcode']   );
						}
						//加账采购 --报价 生成
// 						dd($resJZCG);
						SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_Yjiazhangcbf_HXJZ_BAOJIA' , ['fbillnoentry'=> $v['fbillnoentry'],'Fbm'=>'CG' ] );
						$in= SqlServerUtil::sqlsrvAllTosql($this->SqlServer ,'gz_Yjiazhangcbf_HXJZ_BAOJIA' , $resJZCG);
					}
				}
			}
			
			//正式加账管理  财务部
			if($FRepKey == '34005'){
				// 判断其他部门 是否 已确认
				foreach ($data as $k =>$v)
				{
					if($v['fisqrname']>0){
						showMsg(400,'已完成无法在操作 ！');
					}
					if($v['fisqr'] <1  || empty($v['fqrjs']) ||  empty($v['fqrcg']) )
					{
						showMsg(400,'采购或技术部门还没有确认！');
					}
					
					$resZSQR  = SqlServerUtil::execToSql($this->SqlServer, "select fbillnoentry ,fstatus from gz_YbaojiadanCB_HXJZ where fbillnoentry ='{$v['fbillnoentry']}'  ",2 );
					if($resZSQR){
						//判断是否有值
						if($resZSQR['fstatus']>0){
							showMsg(400,$v['fbillnoentry'].'正式报价加账已审核，无法反确认');
						}
						showMsg(400,$v['fbillnoentry'].'正式报价加账已生成，请删除再反确认');
					}
				}
				
				//财务部部
				$sql="update {$db} set  fisqr = 3, fqrCW = '{$cwname}',opernameCW ='{$opername}', fcreattimeCW='{$time}'  where 1=1 {$FIDStr}   ";
				//参数设置
				$csSetData = $this->getSystemProfile();
				foreach ($data as $k =>&$v)
				{
					//判断加账其他是否已审核
					$sqljs="select v1.fbrand,v1.fprodno, v1.fcode ,v1.fstatus,u1.fname  from gz_YjiazhangcbfMX v1
					inner join gz_YjiazhangcbfSet u1 on u1.fcode=v1.fcode
					where 1=1 and v1.fprodno ='{$v['fmodel']}' 
					and ( charindex('其他',u1.fdanweibumen)>0 or charindex('生产',u1.fdanweibumen)>0  
					or charindex('质量',u1.fdanweibumen)>0  or charindex('售后',u1.fdanweibumen)>0 ) ";
					$rescg  = SqlServerUtil::execToSql($this->SqlServer, $sqljs );
					if($rescg){
						//判断是否有审核
						$one = array_unique(array_column($rescg,'fstatus'));
						if(in_array(0,$one)){
							showMsg(400,'加账其他机型：'.$v['fmodel'].'未审核,请检查');
						}
					}	
					
					////加账 其他
					$sqljz = " select v1.fbrand,v1.fprodno,v1.fywqty,v1.fcode,isnull(t1.fallamount,0) as foriamount,u1.fname,u1.fdanweibumen,
					u1.fqty,u1.fzjqty,u1.ffaxamount as fyzamount,'QT' as fbm  from gz_Yjiazhangcbf_HXJZ  v1
					left join gz_YjiazhangcbfSet u1 on u1.fcode=v1.fcode   
					left join gz_YjiazhangcbfMX t1 on t1.fcode=v1.fcode and t1.fprodno = v1.fprodno  
					where 1=1  and v1.fbillnoentry ='{$v['fbillnoentry']}' and ( charindex('其他',u1.fdanweibumen)>0 or charindex('生产',u1.fdanweibumen)>0  or charindex('质量',u1.fdanweibumen)>0  or charindex('售后',u1.fdanweibumen)>0 )  " ;
					//echo $sqljz;die;
					$resJZQT  = SqlServerUtil::execToSql($this->SqlServer, $sqljz );
				 	
					//其他jiaz  生成
					if($resJZQT){
						foreach ($resJZQT as $kjz =>$vjz)
						{
							if($fisrqr != 1){
								if($vjz['foriamount']<=0){
									showMsg(14009,'代码：'.$vjz['fcode'].'，名称：'.$vjz['fname'].' 输入金额为 0 ，请检查',1);
								}
							}
							
							$resJZQT[$kjz]['fjybjbillno'] = $v['fbillno'];
							$resJZQT[$kjz]['fbillnoentry'] = $v['fbillnoentry'];
							$resJZQT[$kjz]['fax']= $csSetData['fsetffax'] ;
							$resJZQT[$kjz]['fzscjPrice']= $csSetData['fsetrgzhuangshicjprice'] ;
							$resJZQT[$kjz]['fsxqty']= $v['fqty'] ;
							$resJZQT[$kjz]['fbm']= 'QT' ;
							$resJZQT[$kjz]['fqty']= $vjz['fqty'] ;
							$resJZQT[$kjz]['fzjqty']= $vjz['fzjqty'] ;
							$resJZQT[$kjz]['fyzamount']= $vjz['fyzamount'] ;
							$resJZQT[$kjz]['fywqty']= $vjz['fywqty'] ;
							$resJZQT[$kjz]['foriamount']= $vjz['foriamount'] ;//修改金额
							 
							$resJZQT[$kjz]['fallamount']= round( $vjz['foriamount'] *$vjz['fywqty'], 2 ); 
						}
						//加账采购 --报价 生成
						SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_Yjiazhangcbf_HXJZ_BAOJIA' , ['fbillnoentry'=> $v['fbillnoentry'],'Fbm'=>'QT' ] );
						$in= SqlServerUtil::sqlsrvAllTosql($this->SqlServer ,'gz_Yjiazhangcbf_HXJZ_BAOJIA' , $resJZQT);
					}
				
				}	
			}
			
			
		}else{
			if($FRepKey == '14011'){
				foreach ($data as $k=>$v)
				{
					if($v['fisqrname']>0){
						showMsg(400,'已完成无法在操作 ！');
					}
					if($v['fisqr']> 1){
						showMsg(400,'不能反确认，等待采购、财务反确认。');
					}
				}
				//技术部
				$sql="update {$db} set  fisqr = 0 ,opernameJS ='{$opername}',fcreattimeJS =null  where 1=1 {$FIDStr}   ";
			}
			
			if($FRepKey == '14012'){
				foreach ($data as $k=>$v)
				{
					if($v['fisqrname']>0){
						showMsg(400,'已完成无法在操作 ！');
					}
					
					if($v['fisqr']> 2){
						showMsg(400,'不能反确认，等待财务反确认。');
					}
				}
				//采购部
				$sql="update {$db} set  fisqr = 0, fqrJS = '' ,opernameCG ='{$opername}' ,fcreattimeCG =null where 1=1 {$FIDStr}   ";
			}
				
			if($FRepKey == '14013'){
				//这个
				//财务 -- 反确认 
				foreach ($data as $k=>$v)
				{
					if($v['fisqrname']>0){
						showMsg(400,'已完成无法再操作 ！');
					}
					
					$resZSQR  = SqlServerUtil::execToSql($this->SqlServer, "select fbillno,fstatus from gz_YbaojiadanCB where fbillno ='{$v['fbillno']}'  ",2 );
					if($resZSQR){
						//判断是否有值 
						if($resZSQR['fstatus']>0){
							showMsg(400,$v['fbillno'].'正式报价已审核，无法反确认');
						}
						showMsg(400,$v['fbillno'].'正式报价已生成，请删除再反确认');
					}
				//燃油  汇总
// 				SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_YranyouHZ_BAOJIA' , ['fjybjbillno'=> "'".$v['fbillno']."'" ],true);
// 				SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_YranyouHZ' , ['fbillno'=> "'".$v['fbillno']."'" ],true);
				// 加账SCR/ICER
				SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_YjzSCREGRHZ' , ['fbillno'=> "'".$v['fbillno']."'" ],true);
				
				SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_YjzSCREGRNOcbHZ' , ['fbillno'=> "'".$v['fbillno']."'" ],true);
				SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_YjzICERRanYouHZ' , ['fbillno'=> "'".$v['fbillno']."'" ],true);
				SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_YjzICERQT' , ['fbillno'=> "'".$v['fbillno']."'" ],true);
				SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_YjzECOEGRNOcbHZ' , ['fbillno'=> "'".$v['fbillno']."'" ],true);
				SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_YjzJiaChunQT' , ['fbillno'=> "'".$v['fbillno']."'" ],true);
				}
				$sql="update {$db} set  fisqr = 0, fqrCW = '',fqrCG = '' ,fqrJS = '' ,opernameCW ='{$opername}',
 					fcreattimeJS =null,fcreattimeCG =null,fcreattimeCW =null  where 1=1 {$FIDStr}   "; 
			}
			
			if($FRepKey == '34005' ){
				//正式报价 加账-反确认  
				foreach ($data as $k=>$v)
				{
					if($v['fisqrname']>0){
						showMsg(400,'已完成无法在操作 ！');
					}
					$resJZQR  = SqlServerUtil::execToSql($this->SqlServer, "select fbillnoentry,fstatus from gz_YbaojiadanCB_HXJZ where fbillnoentry ='{$v['fbillnoentry']}'   ",2 );
					if($resJZQR){
						//判断是否审核 
						if($resJZQR['fstatus']>0){
							showMsg(400,$v['fbillnoentry'].'正式报价加账已审核，无法反确认');
						}
						showMsg(400,$v['fbillnoentry'].'正式报价加账已生成，请删除再反确认');
					}
					SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_Yjiazhangcbf_HXJZ_BAOJIA' , ['fbillnoentry'=> "'".$v['fbillnoentry']."'" ],true);
				}
				$sql="update {$db} set  fisqr = 1, fqrCW = '',fqrCG = '' ,fqrJS = '' ,opernameCW ='{$opername}' ,fcreattimeCG =null,fcreattimeJS =null ,fcreattimeCW =null where 1=1 {$FIDStr}   ";
			}
			
		  }
		 
		}
	// 启动事务
	if (sqlsrv_begin_transaction($this->SqlServer) === false) {
		die(print_r(sqlsrv_errors(), true));
	}
// 	echo $sql;die; 
	$sqlStr = iconv( 'UTF-8','GBK',$sql);
	$up = sqlsrv_query($this->SqlServer, $sqlStr);
	if($up  ){
		sqlsrv_commit($this->SqlServer);
		showMsg(0,'成功');
	}else {
		sqlsrv_rollback($this->SqlServer);
		showMsg(1,'失败');
	}
	showMsg(0);
		
	}
	
	/*
	* 正式报价 0反审  ，  反确认  （财务部点击反确认 ） 1-技术
	* @date: 2023年4月27日 下午8:28:40
	* @author: juyi
	*/
	public function FstatusZS(Request $request){
		$FRepKey = $request->get('FRepKey');
		$loginname = $request->get('loginname');
		$isfanshen  = $request->isfanshen??0;
		$opername = $loginname ;
		if(empty($loginname)){
			showMsg(1,'审核名称不能为空');
		}
		$FIDStr='';
		$FItemidStr='';
		if ($request->has('fid') and $request->fid != '' and !empty($request->fid)) {
			$FID = $request->fid;
			$FIDStr=" and fid in ($FID) ";
			$FItemidStr=" and fitemid in ($FID) ";
		}
		
		$db = columnBiao($FRepKey);
		$Fstatus = $request->get('Fstatus'); //1--审核，0--反审
		$data = $request->data ;
		//正式报价加账业务 - 反审
		if($isfanshen == 0){
			if($Fstatus == 0){
				foreach ($data as $k =>$v){
					if($v['fisqrname']>0){
						showMsg(400,'已完成无法在操作 ！');
					}
					$resZSQR  = SqlServerUtil::execToSql($this->SqlServer, "select fbillno,fstatus from gz_YbaojiadanCB  where fbillno ='{$v['fbillno']}' ",2 );
					if($resZSQR){
						if( $resZSQR['fstatus']> 0 ){
							showMsg(400,$v['fbillno'].'正式报价已审核，无法再反审');
						}
						showMsg(400,$v['fbillno'].'正式报价已生成，先删除再反审');
					}
					// 加账SCR/ICER
					SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_YjzSCREGRHZ' , ['fbillno'=> "'".$v['fbillno']."'" ],true);
					
					SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_YjzSCREGRNOcbHZ' , ['fbillno'=> "'".$v['fbillno']."'" ],true);
					SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_YjzICERRanYouHZ' , ['fbillno'=> "'".$v['fbillno']."'" ],true);
					SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_YjzICERQT' , ['fbillno'=> "'".$v['fbillno']."'" ],true);
					SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_YjzECOEGRNOcbHZ' , ['fbillno'=> "'".$v['fbillno']."'" ],true);
					SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_YjzJiaChunQT' , ['fbillno'=> "'".$v['fbillno']."'" ],true);
					
					 
				}
				$sql="update {$db} set  fisqr = 2, fqrCW = '',fcreattimeCW =null  where 1=1 {$FIDStr}   ";
			}
		}elseif($isfanshen == 1){
			 //技术
			foreach ($data as $k =>$v){
				if($v['fisqrname']>0){
					showMsg(400,'已完成无法在操作 ！');
				}
				$resZSQR  = SqlServerUtil::execToSql($this->SqlServer, "select fbillno,fstatus from gz_YbaojiadanCB  where fbillno ='{$v['fbillno']}' ",2 );
				if($resZSQR){
					if( $resZSQR['fstatus']> 0 ){
						showMsg(400,$v['fbillno'].'正式报价已审核，无法再反审');
					}
					showMsg(400,$v['fbillno'].'正式报价已生成，先删除再反审');
				}
				// 加账SCR/ICER
				SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_YjzSCREGRHZ' , ['fbillno'=> "'".$v['fbillno']."'" ],true);
				
				SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_YjzSCREGRNOcbHZ' , ['fbillno'=> "'".$v['fbillno']."'" ],true);
				SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_YjzICERRanYouHZ' , ['fbillno'=> "'".$v['fbillno']."'" ],true);
				SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_YjzICERQT' , ['fbillno'=> "'".$v['fbillno']."'" ],true);
				SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_YjzECOEGRNOcbHZ' , ['fbillno'=> "'".$v['fbillno']."'" ],true);
				SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_YjzJiaChunQT' , ['fbillno'=> "'".$v['fbillno']."'" ],true);
				
			}
			
			 
			$sql="update {$db} set  fisqr = 0, fqrCW = '',fqrJS = '' ,opernameCW ='',opernameJS ='',
			fcreattimeJS =null ,fcreattimeCW =null   where 1=1 {$FIDStr}   ";
			
			
		}elseif($isfanshen == 2){
			foreach ($data as $k =>$v){
				if($v['fisqrname']>0){
					showMsg(400,'已完成无法在操作 ！');
				}
				$resZSQR  = SqlServerUtil::execToSql($this->SqlServer, "select fbillno,fstatus from gz_YbaojiadanCB  where fbillno ='{$v['fbillno']}' ",2 );
				if($resZSQR){
					if( $resZSQR['fstatus']> 0 ){
						showMsg(400,$v['fbillno'].'正式报价已审核，无法再反审');
					}
					showMsg(400,$v['fbillno'].'正式报价已生成，先删除再反审');
				}
				// 加账SCR/ICER
				SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_YjzSCREGRHZ' , ['fbillno'=> "'".$v['fbillno']."'" ],true);
				
				SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_YjzSCREGRNOcbHZ' , ['fbillno'=> "'".$v['fbillno']."'" ],true);
				SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_YjzICERRanYouHZ' , ['fbillno'=> "'".$v['fbillno']."'" ],true);
				SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_YjzICERQT' , ['fbillno'=> "'".$v['fbillno']."'" ],true);
				SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_YjzECOEGRNOcbHZ' , ['fbillno'=> "'".$v['fbillno']."'" ],true);
				SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_YjzJiaChunQT' , ['fbillno'=> "'".$v['fbillno']."'" ],true);
				
				
			}
			
			//采购部
			$sql="update {$db} set  fisqr = 1, fqrCW = '',fqrCG = '' ,opernameCW ='',opernameCG ='',fcreattimeCG =null ,fcreattimeCW =null   where 1=1 {$FIDStr}   ";
			
		}
		// 启动事务
		if (sqlsrv_begin_transaction($this->SqlServer) === false) {
			die(print_r(sqlsrv_errors(), true));
		}
		$temp='';
		if($isfanshen==1){
			$temp = '反技术';
		}elseif($isfanshen==2){
			$temp = '反采购';
		}else{
			$temp = '反审';
		}
		$this->writeLog(getMkName($FRepKey),$temp , $FRepKey ,$request->all() ,$loginname );
		//echo $sql;die;
		$sqlStr = iconv( 'UTF-8','GBK',$sql);
		$up = sqlsrv_query($this->SqlServer, $sqlStr);
		if($up  ){
			sqlsrv_commit($this->SqlServer);
			showMsg(0,'成功');
		}else {
			sqlsrv_rollback($this->SqlServer);
			showMsg(1,'失败');
		}
	}
	
	/*
	 * 正式报价加账   反审  ，  反确认  （财务部点击反确认 ）  加账
	 * @date: 2023年4月27日 下午8:28:40
	 * @author: juyi
	 */
	public function FstatusZSJZ(Request $request){
		$FRepKey = $request->get('FRepKey');
		$loginname = $request->get('loginname');
		$isfanshen  = $request->isfanshen??0;
		$opername = $loginname ;
		if(empty($loginname)){
			showMsg(1,'审核名称不能为空');
		}
		$FIDStr='';
		$FItemidStr='';
		if ($request->has('fid') and $request->fid != '' and !empty($request->fid)) {
			$FID = $request->fid;
			$FIDStr=" and fid in ($FID) ";
			$FItemidStr=" and fitemid in ($FID) ";
		}
		
		$db = columnBiao($FRepKey);
		$Fstatus = $request->get('Fstatus'); //1--审核，0--反审
		$data = $request->data ;
		//正式报价加账业务 - 反审
		if($isfanshen == 0){
			if($Fstatus == 0){
				foreach ($data as $k =>$v){
					if($v['fisqrname']>0){
						showMsg(400,'已完成无法在操作 ！');
					}
					$resZSQR  = SqlServerUtil::execToSql($this->SqlServer, "select fbillno,fstatus,fbillnoentry from gz_YbaojiadanCB_HXJZ where fbillnoEntry ='{$v['fbillnoentry']}' ",2 );
					if($resZSQR){
						if( $resZSQR['fstatus']> 0 ){
							showMsg(400, '流水号：'.$v['fbillnoentry'].',正式报价加账已审核，无法再反审');
						}
						showMsg(400, '流水号：'.$v['fbillnoentry'].',正式报价加账已生成，先删除再反审');
					}
				}
				$sql="update {$db} set  fisqr = 2, fqrCW = '',fcreattimeCW =null  where 1=1 {$FIDStr}   ";
			}
		}elseif($isfanshen == 1){
			//技术
			foreach ($data as $k =>$v){
				if($v['fisqrname']>0){
					showMsg(400,'已完成无法在操作 ！');
				}
				$resZSQR  = SqlServerUtil::execToSql($this->SqlServer, "select fbillno,fstatus,fbillnoentry from gz_YbaojiadanCB_HXJZ  where fbillnoentry ='{$v['fbillnoentry']}' ",2 );
				if($resZSQR){
					if( $resZSQR['fstatus']> 0 ){
						showMsg(400,'流水号：'.$v['fbillnoentry'].',正式报价加账已审核，无法再反审');
					}
					showMsg(400,'流水号：'.$v['fbillnoentry'].',正式报价加账已生成，先删除再反审');
				}
			}
			
			$sql="update {$db} set  fisqr = 0, fqrCW = '',fqrJS = '' ,opernameCW ='',opernameJS ='',
			fcreattimeJS =null ,fcreattimeCW =null   where 1=1 {$FIDStr}   ";
			
		}elseif($isfanshen == 2){
			foreach ($data as $k =>$v){
				if($v['fisqrname']>0){
					showMsg(400,'已完成无法在操作 ！');
				}
				$resZSQR  = SqlServerUtil::execToSql($this->SqlServer, "select fbillno,fstatus,fbillnoentry from gz_YbaojiadanCB_HXJZ  where fbillnoentry ='{$v['fbillnoentry']}' ",2 );
				if($resZSQR){
					if( $resZSQR['fstatus']> 0 ){
						showMsg(400,'流水号：'.$v['fbillnoentry'].',正式报价已审核，无法再反审');
					}
					showMsg(400,'流水号：'.$v['fbillnoentry'].',正式报价已生成，先删除再反审');
				}
			}
			//采购部
			$sql="update {$db} set  fisqr = 1, fqrCW = '',fqrCG = '' ,opernameCW ='',opernameCG ='',fcreattimeCG =null ,fcreattimeCW =null   where 1=1 {$FIDStr}   ";
			
		}
		// 启动事务
		if (sqlsrv_begin_transaction($this->SqlServer) === false) {
			die(print_r(sqlsrv_errors(), true));
		}
		$temp='';
		if($isfanshen == 1){
			$temp = '反技术';
		}elseif($isfanshen == 2){
			$temp = '反采购';
		}else{
			$temp = '反审';
		}
		$this->writeLog(getMkName($FRepKey),$temp , $FRepKey ,$request->all() ,$loginname );
		//echo $sql;die;
		$sqlStr = iconv( 'UTF-8','GBK',$sql);
		$up = sqlsrv_query($this->SqlServer, $sqlStr);
		if($up  ){
			sqlsrv_commit($this->SqlServer);
			showMsg(0,'成功');
		}else {
			sqlsrv_rollback($this->SqlServer);
			showMsg(1,'失败');
		}
	}
	
	
	
	
	/**
	*  正式报价 ， 正式加账，经营报价  --  退审 
	* @date: 2023年4月28日 上午11:18:13
	* @author: juyi
	*/
	public function FstatusTS(Request $request){
		$FRepKey = $request->get('FRepKey');
		$loginname = $request->get('loginname');
		$isfanshen  = $request->isfanshen??0;
		$opername = $loginname ;
		if(empty($loginname)){
			showMsg(1,'审核名称不能为空'); 
		}
		$FIDStr = '';
		$FItemidStr = '';
		if ($request->has('fid') and $request->fid != '' and !empty($request->fid)) {
			$FID = $request->fid;
			$FIDStr=" and fid in ($FID) ";
			$FItemidStr=" and fitemid in ($FID) ";
		}
		
		$db = columnBiao($FRepKey);
		$Fstatus = $request->get('Fstatus'); //1--审核，0--反审  
		$data = $request->data ;
		
		if($FRepKey == '14011'){
			//技术
			foreach ($data as $k =>$v){
				if($v['fisqrname']>0){
					showMsg(400,'已完成无法在操作 ！');
				}
				if($v['fisqr']>2){
					showMsg(400,'财务已确认，无法在操作 ！');
				}
				if(!empty($v['fqrcg'])  || !empty($v['fqrcw'])  ){
					showMsg(400,'采购或财务已确认，无法在操作 ！');
				}
				if($v['fisqrname']>0){
					showMsg(400,'已完成无法在操作 ！');
				}
				$resZSQR  = SqlServerUtil::execToSql($this->SqlServer, "select fbillno,fstatus from gz_YbaojiadanCB  where fbillno ='{$v['fbillno']}' ",2 );
				if($resZSQR){
					if( $resZSQR['fstatus']> 0 ){
						showMsg(400,'流水号 :'.$v['fbillno'].'正式报价已审核，无法再退审');
					}
					showMsg(400,'流水号 :'.$v['fbillno'].'正式报价已生成，先删除再退审');
				}
				
				//加账技术 --报价 生成
				SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_Yjiazhangcbf_BAOJIA' , ['fjybjbillno'=> $v['fbillno'],'Fbm'=>'JS' ]);
				
			}
			
			$sql="update {$db} set fstatus = 0, fisqr = 0,fqrcg='',fqrJS = '', fqrCW = '' ,opernameCW ='',opernameJS ='',opernameCG ='' ,
			fcreattimeCG =null ,fcreattimeJS =null ,fcreattimeCW =null  where 1=1 {$FIDStr}   ";
		}elseif($FRepKey == '14012'){
			// 采购 
			foreach ($data as $k =>$v){
				if($v['fisqrname']>0){
					showMsg(400,'已完成无法在操作 ！');
				}
				if($v['fisqr']>2){
					showMsg(400,'财务已确认，无法在操作 ！');
				}
				if( !empty($v['fqrcw'])  ){
					showMsg(400,'财务已确认，无法在操作 ！');
				}
				if($v['fisqrname']>0){
					showMsg(400,'已完成无法在操作 ！');
				}
				$resZSQR  = SqlServerUtil::execToSql($this->SqlServer, "select fbillno,fstatus from gz_YbaojiadanCB  where fbillno ='{$v['fbillno']}' ",2 );
				if($resZSQR){
					if( $resZSQR['fstatus']> 0 ){
						showMsg(400,'流水号 :'.$v['fbillno'].'正式报价已审核，无法再退审');
					}
					showMsg(400,'流水号 :'.$v['fbillno'].'正式报价已生成，先删除再退审');
				}
				
				//判断是否已经生成SCR/ICER
				$resSCR  = SqlServerUtil::execToSql($this->SqlServer, "select fbillno  from gz_YjzSCREGRHZ  where fbillno ='{$v['fbillno']}' ",2 );
				if($resSCR){
					showMsg(400,'流水号 :'.$v['fbillno'].' 加账SCR/ICER管理，已生成 ,无法再退审, 请联系财务');
				}
				
				//加账 采购    --报价 生成
				SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_Yjiazhangcbf_BAOJIA' , ['fjybjbillno'=> $v['fbillno']  ]);
				
				
			}
			$sql="update {$db} set fisqr = 0, fqrJS = '',fqrCG = '', fqrCW = '' ,opernameCW ='',opernameJS ='',opernameCG ='',
		 fcreattimeCG =null ,fcreattimeJS =null ,fcreattimeCW =null  where 1=1 {$FIDStr}   ";
			
			
		}elseif($FRepKey == '34002'){
			//正式报价    加账技术 
			foreach ($data as $k =>$v){
				if($v['fisqrname']>0){
					showMsg(400,'已完成无法在操作 ！');
				}
				if($v['fisqr']>2){
					showMsg(400,'财务已确认，无法在操作 ！');
				}
				if(!empty($v['fqrcg'])  || !empty($v['fqrcw'])  ){
					showMsg(400,'采购或财务已确认，无法在操作 ！');
				}
				if($v['fisqrname']>0){
					showMsg(400,'已完成无法在操作 ！');
				}
				$resZSQR  = SqlServerUtil::execToSql($this->SqlServer, "select fbillno,fstatus,fbillnoentry from gz_YbaojiadanCB_HXJZ  where fbillnoentry ='{$v['fbillnoentry']}' ",2 );
				if($resZSQR){
					if( $resZSQR['fstatus']> 0 ){
						showMsg(400,'流水号子订单：'.$v['fbillnoentry'].'，正式报价已审核，无法再退审');
					}
					showMsg(400,'流水号子订单：'.$v['fbillnoentry'].'，正式报价已生成，先删除再退审');
				}
				 
			}
			
			$sql="update {$db} set fstatus = 0, fisqr = 0,fqrcg='',fqrJS = '', fqrCW = '' ,opernameCW ='',opernameJS ='',opernameCG =''  where 1=1 {$FIDStr}   ";
		}elseif($FRepKey == '34003'){
			// 加账采购
			foreach ($data as $k =>$v){
				if($v['fisqrname']>0){
					showMsg(400,'已完成无法在操作 ！');
				}
				if($v['fisqr']>2){
					showMsg(400,'财务已确认，无法在操作 ！');
				}
				if( !empty($v['fqrcw'])  ){
					showMsg(400,'财务已确认，无法在操作 ！');
				}
				if($v['fisqrname']>0){
					showMsg(400,'已完成无法在操作 ！');
				}
				$resZSQR  = SqlServerUtil::execToSql($this->SqlServer, "select fbillno,fstatus,fbillnoentry from gz_YbaojiadanCB_HXJZ  where fbillnoentry ='{$v['fbillnoentry']}' ",2 );
				if($resZSQR){
					if( $resZSQR['fstatus']> 0 ){
						showMsg(400,'流水号子订单：'.$v['fbillnoentry'].'正式报价已审核，无法再退审');
					}
					showMsg(400,'流水号子订单：'.$v['fbillnoentry'].'正式报价已生成，先删除再退审');
				}
				
			}
			$sql="update {$db} set fisqr = 0, fqrJS = '',fqrCG = '', fqrCW = '' ,opernameCW ='',opernameJS ='',opernameCG =''  where 1=1 {$FIDStr}   ";
			
			
		}elseif($FRepKey == '30005'){
			//经营报价  --  经营技术
			foreach ($data as $k =>$v){
				if($v['fisqrname']>0){
					showMsg(400,'已完成无法在操作 ！');
				}
				if($v['fisqr']>2){
					showMsg(400,'财务已确认，无法在操作 ！');
				}
				if(!empty($v['fqrcg'])  || !empty($v['fqrcw'])  ){
					showMsg(400,'采购或财务已确认，无法在操作 ！');
				}
				if($v['fisqrname']>0){
					showMsg(400,'已完成无法在操作 ！');
				}
				$resZSQR  = SqlServerUtil::execToSql($this->SqlServer, "select fbillno,fstatus from gz_YbaojiadanZLCCG  where fbillno ='{$v['fbillno']}' ",2 );
				if($resZSQR){
					if( $resZSQR['fstatus']> 0 ){
						showMsg(400,$v['fbillno'].'正式报价已审核，无法再退审');
					}
					showMsg(400,$v['fbillno'].'正式报价已生成，先删除再退审');
				}
			}
			
			$sql="update {$db} set fstatus = 0, fisqr = 0,fqrcg='',fqrJS = '', fqrCW = '' ,opernameCW ='',opernameJS ='',opernameCG =''  where 1=1 {$FIDStr}   ";
		}elseif($FRepKey == '30006'){
			// 经营采购  
			foreach ($data as $k =>$v){
				if($v['fisqrname']>0){
					showMsg(400,'已完成无法在操作 ！');
				}
				if($v['fisqr']>2){
					showMsg(400,'财务已确认，无法在操作 ！');
				}
				if( !empty($v['fqrcw'])  ){
					showMsg(400,'财务已确认，无法在操作 ！');
				}
				if($v['fisqrname']>0){
					showMsg(400,'已完成无法在操作 ！');
				}
				$resZSQR  = SqlServerUtil::execToSql($this->SqlServer, "select fbillno,fstatus from gz_YbaojiadanZLCCG  where fbillno ='{$v['fbillno']}' ",2 );
				if($resZSQR){
					if( $resZSQR['fstatus']> 0 ){
						showMsg(400,$v['fbillno'].'正式报价已审核，无法再退审');
					}
					showMsg(400,$v['fbillno'].'正式报价已生成，先删除再退审');
				}
			}
			$sql="update {$db} set fisqr = 0, fqrJS = '',fqrCG = '', fqrCW = '' ,opernameCW ='',opernameJS ='',opernameCG =''  where 1=1 {$FIDStr}   ";
		}
		
		// 启动事务
		if (sqlsrv_begin_transaction($this->SqlServer) === false) {
			die(print_r(sqlsrv_errors(), true));
		}
		
		$this->writeLog(getMkName($FRepKey), '退审' , $FRepKey ,$request->all() ,$loginname );
		// 		echo $sql;die;
		$sqlStr = iconv( 'UTF-8','GBK',$sql);
		$up = sqlsrv_query($this->SqlServer, $sqlStr);
		if($up  ){
			sqlsrv_commit($this->SqlServer);
			showMsg(0,'成功');
		}else {
			sqlsrv_rollback($this->SqlServer);
			showMsg(1,'失败');
		}
		
		
	}
	
	
	/**
	*  权限 -- 左侧栏 显示 
	* @date: 2023年9月13日 下午3:45:13
	* @author: juyi
	*/
	function FQXLeftView(Request $request){
		//菜单列表
		$sql = "select fobjecttype,fobjectid,fname,fdescription from gz_objecttype where fobjecttype>=90000 and fobjectid=0 and fobjecttype in (select distinct fobjecttype from gz_objectfunc where FObjHide=0) order by fobjecttype,fobjectid";
		$menuData = SqlServerUtil::execToSql($this->SqlServer, $sql);
		
		$sql1 = "select distinct t1.fobjecttype,t1.fobjectid,t1.fname,t1.fdescription from gz_objecttype t1 
		where   t1.fobjectid>0 and t1.fobjectid in (select distinct fobjectid from gz_objectfunc where FObjHide=0 and FIndex=0) 
		order by t1.fobjecttype,t1.fobjectid ";
		$menulistData = SqlServerUtil::execToSql($this->SqlServer, $sql1);
		$result=[];
		if($menuData && $menulistData){
			foreach ($menuData as $k=>$v )
			{
				$menuData[$k]['icon'] = geticon($v['fobjecttype']) ;
				foreach ($menulistData as $k1=>$v1 )
				{
					if($v['fobjecttype'] == $v1['fobjecttype']){
						$menuData[$k]['child'][] = $v1;
					}
				}
			}
			showMsg(0,'成功',$menuData );
		}
		showMsg(1,'数据为空重新设置');
	}
	
	/**
	* 文件用途描述
	* @date: 2023年9月13日 下午3:47:14
	* @author: juyi
	*/
	function FQXRightContent(Request $request){
		$fobjecttype = $request->get('fobjecttype');
		$fobjectid = $request->get('fobjectid');
		if(empty($fobjecttype) || empty($fobjectid)){
			showMsg(1,'参数错误，请重试！');
		}
		$sql = "select FObjectType,FObjectID,FIndex,FAccessMask,FName from gz_objectaccesstype 
		where fobjecttype='{$fobjecttype}' and fobjectid='{$fobjectid}' order by findex";
		$menulist = SqlServerUtil::execToSql($this->SqlServer, $sql);
		showMsg(0,'成功',$menulist );
	}
	
	
	/**
	* 权限 详情显示 
	* @date: 2023年9月14日 下午3:19:37
	* @author: juyi
	*/
	function getQXDetail(Request $request){
		$data = $request->get('data');
		if(empty($data)){
			showMsg(1,'请选择一个用户组');
		}
		$groupID = $data['id'] ; //组
		$sql =" SELECT v1.FObjectType , v1.FObjectID ,v1.FAccessMask ,v1.Fsqlist ,u2.FName as mainName ,u1.FName as zhiName
		FROM  gz_AccessControl_group v1
		left join gz_ObjectType u2 on  u2.FObjectType = v1.FObjectType  and u2.FObjectID = 0
		left join gz_ObjectType u1 on  u1.FObjectType = v1.FObjectType  and u1.FObjectID = v1.FObjectID
		where v1.FUserID = '{$groupID}'  
		ORDER BY v1.FObjectType , v1.FObjectID " ;
		$QXData = SqlServerUtil::execToSql($this->SqlServer, $sql);
// 		if(empty($QXData)){
// 			showMsg(1,'该用户组  ,暂时没给权限，请检查');
// 		}
		$FObjectType = join (',', array_unique ( array_column($QXData,'FObjectType') ) ) ;
		$FObjectID = join (',', array_unique ( array_column($QXData,'FObjectID') ) ) ;
		
		$sql = "select FObjectType,FObjectID ,FIndex,FAccessMask,FName  from gz_ObjectAccessType
		where FObjectType in ({$FObjectType} ) and FObjectID in ({$FObjectID} ) ORDER BY  FObjectType,FObjectID ,FIndex ";
		$ObjectAccess = SqlServerUtil::execToSql($this->SqlServer, $sql);
		
		$result = [];
		if($QXData){
			foreach ($QXData as $k =>&$v){
				$v['QXListStr']  ='';
				foreach ($ObjectAccess as $k1 =>$v1){
					if($v['FObjectType'] == $v1['FObjectType'] && $v['FObjectID'] == $v1['FObjectID']  ){
						$temp = explode( ',', $v['Fsqlist']); 
						foreach ($temp as $k2 =>$v2){
							if($v2 == $v1['FAccessMask']){
								$v['QXListStr']  .= ','.$v1['FName'];
							}
						}
						
					}
					
				}
				$v['QXListStr'] = ltrim($v['QXListStr'],',');
			}
			
		}
		showMsg(0,'成功',$QXData );
	}
	
	/**
	* 导入字段 
	* @date: 2023年9月20日 下午5:45:57
	* @author: juyi
	*/
	function getImportField(Request $request){
		$FRepKey = $request->FRepKey ;
		$FRepPage  = $request->FRepPage??0 ;
		
		$sql = "select frepfld,frepcap,frepmeg from gz_RepListTitle 
		where FRepKey ='{$FRepKey}' and  FRepPage = '0' and FRepHide =0  and FuploadFile = 0 order by FRepIndex";
		
		$SetCodeData = SqlServerUtil::execToSql($this->SqlServer,$sql);
		
		showMsg(0,'成功',$SetCodeData );
	}
	
	
	
	
	

}
